Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-17-2008, 07:34 AM   #1
nareshmac
Registered User
 
Join Date: Apr 2008
Posts: 1
Jaguar Including a dylib and using

Hi friends,
I am able to develop a dylib using Xcode,
1)Can any one tell me how to include or use it in other applications ?

2)Other than Xcode , any other way to develop a dylib and use it with other applications ?

please give me a solution,

Thnaks,
knrcse
nareshmac is offline   Reply With Quote
Old 04-23-2008, 12:01 PM   #2
nijm
Triple-A Player
 
Join Date: Jul 2006
Posts: 85
Hmm... I'm surprised nobody has answered this yet. This is actually simple to do (but kind of hard to find out how to do):

1) Write your dylib source code normally. Use an IDE (Xcode, or whatever), or use a text editor (emacs, textwrangler, whatever). This is usually just a class or a collection of related functions. Just normal c, c++, or obj-c, or whatever.
2) Compile using gcc, and in addition to whatever flags you normally use, add the flags -dynamiclib -o /full/path/to/dylib/final/destination/libname_of_dylib.dylib.
3) In your .profile, add the path to your dylib (but not the name of the dylib) into the environment variable LIBRARY_PATH.
4) If you don't want to have to type -I/full/path/to/the/header/file/of/your/dylib every time you compile something that uses your new dylib, you can add the path to its header into the environment variable CPLUS_INCLUDE_PATH (again, in .profile).
5) Now when you write something that uses the dylib, do an #include <name_of_dylib_header_file.h> in your source file, and at compile time, use the flag -lname_of_dylib (that's a lowercase "L" after the "-").


A couple of footnotes:
You want to prepend the dylib with lib, but don't use it when you link (-lname_of_dylib). The same goes for the suffix .dylib.

If you compile your dylib, but want to move it later, then it will break unless you use the flag -install_name /full/path/to/dylib/final/destination/libname_of_dylib.dylib. This is necessary for the linker to work properly. This writes a reference in the header part of the dylib so the linker knows where to look for it (I know, it seems like if the linker found it in the first place, it should know where to find it, no? There is probably a good reason that this is necessary, I just don't know what it is). If you do not use the -install_name flag, it just writes whatever you put after -o in this position in the head of the dylib.

You can exclude step 3. If you do, then you will need to use the flag -L/full/path/to/dylib/final/destination when you compile you application that uses the dylib (again, excluding the name of the dylib).

I suggest reading the man pages for: gcc, otool, and ld.
nijm is offline   Reply With Quote
Old 05-02-2008, 02:52 PM   #3
dmacks
All Star
 
Join Date: Dec 2004
Posts: 677
The -install_name encoding in the .dylib is propagated into things that link against it. Then those things know exactly where to find that .dylib at runtime instead of having to search through env vars and lots of other "standard" places to find it.
dmacks is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:42 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.