 |
 |
How to use a "dynlib"
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Status:
Offline
|
|
I've been able to create a dynlib with the configure/makefiles in a port of a linux softare project but I've not been able to find how to link to it. While if Apple ported ld properly, the flag is supposed to be -l, but apple kinda destroyed that flag by making it search only for static libs. Also, is it just something with Apple's libtools that when I add a libx.al to a higher level source dir's Makefile.am's LDADD that it repeats that target twice in its command to g++ causing linking errors?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2001
Status:
Offline
|
|
If you are using Project Builder, select the target that you are want to link the library into and under "Settings", find the "Other Mach-O Linker Settings" field. Add your desired library and path to that field by adding (for example):
-L/sw/lib -lbz2 (that second one starts with a captial L)
Also add the following to the "Other C Compiler Flags" field if you are including files that have to do with this library (which you most likely are, unless you are loading symbols manually):
-I/sw/include (that's a captial i)
Those two lines will allow you to link to a copy of libbz installed by Fink, and to access the include file via #include <bzlib.h>.
If you are simplying using GCC to compile your source, add the two above lines as agruments to GCC on the command line. Finally, if you are doing a configure, make, make install; simply set the environment variable "LDFLAGS" to the first line and "CPPFLAGS" to the second line. Any copy of autoconf, make, or gcc run in a subshell should pick that up and look for libraries and includes at those paths.
|
|
"Think Different. Like The Rest Of Us."
iBook G4/1.2GHz | 1.25GB | 60GB | Mac OS X 10.4.2
Athlon XP 2500+/1.83GHz | 1GB PC3200 | 120GB | Windows XP
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Apr 2003
Status:
Offline
|
|
I think you misunderstood my post.
I am not using ProjectBuilder.
I am not a newbie! I've been programming for quite some time but just never with OS X. While -l is the correct linker flag under real Unix/Linux systems, according to the MacOS X hacks of the GNU docs,
-l ONLY searches for .a libraries, which are STATIC libraries. I don't want to use static libraries, I'm using shared libraries... Which Apple calls dylibs.
I need to know the flags to specify by command line to specify a dylib.
I've found that you can link to one by giving the exact path without flags but the problem is it only worked for the library that was in a random dir. I tried the path to the lib in /usr/lib(Actually they are soft links to the real lib, mabye Mac OSX doesn't support it right?) but ld couldn't find it.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2001
Status:
Offline
|
|
Originally posted by tk_r00t:
I am not a newbie!
My mistake! I started my C education on OS X, so I forgot that it links differently than, well, any other OS!
Basically it goes like this: OS X won't statically link anything unless you specifically tell it to, and even then it won't work very well since there aren't static versions of most of the standard OS X system libraries. Take for example, the following code:
Code:
#include <stdio.h>
#include <curl/curl.h>
int main() {
CURL *ref;
ref = curl_easy_init();
curl_easy_cleanup( ref );
return 0;
}
Compiled and examined as such:
Code:
$ gcc -I/sw/include -L/sw/lib -lcurl -o test test.c
$ otool -L test
/sw/lib/libcurl.2.dylib (compatibility version 3.0.0, current version 3.2.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 63.0.0)
As you can see, with only the simplest of settings, the object file is dynamically linked. In fact, if I specify -static on the gcc command line, it refuses to link at all, and ld complains that the file for -lcrt0.o cannot be found.
Sorry if this was too long of a response for a question that could have been answered with "dynamic linking only", but, quite frankly, I had forgotten...
|
|
"Think Different. Like The Rest Of Us."
iBook G4/1.2GHz | 1.25GB | 60GB | Mac OS X 10.4.2
Athlon XP 2500+/1.83GHz | 1GB PC3200 | 120GB | Windows XP
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
To put it more simply, "-l ONLY searches for .a libraries" is incorrect. It will do what you want.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|