Re: How to properly add libraries
Re: How to properly add libraries
- Subject: Re: How to properly add libraries
- From: Andreas Grosam <email@hidden>
- Date: Sat, 10 Dec 2011 09:45:17 +0100
On Dec 10, 2011, at 3:30 AM, Kelvin Chung wrote:
> I'm having trouble getting my program to run in XCode. My project relies on a few boost libraries that use automatic linking (boost::thread, etc).
Not sure, if automatic linking is possible on Mac OS X with Xcode.
> Suppose that the path to the boost libs is "~/Downloads/boost/lib". If I add that to the library search path, then the build fails. If I go into "Link Binary With Libraries" in "Build Phases" and add the specific libs required (libboost_system.a and libboost_thread.a) from the lib directory, the code compiles, but crashes on running. GDB gives these warnings:
>
> warning: Unable to read symbols for libboost_system.dylib (file not found).
> warning: Unable to read symbols from "libboost_system.dylib" (not yet mapped into memory).
> warning: Unable to read symbols for libboost_thread.dylib (file not found).
> warning: Unable to read symbols from "libboost_thread.dylib" (not yet mapped into memory).
>
Hm, sounds there the settings are not correct.
You linked against *static* libraries via "Link Binary With Libraries" in "Build Phases", namely the libboost_system.a and libboost_thread.a. static libraries. However, the above warning indicates you linked against dynamic libraries as well, somewhere in your project settings.
> Then it crashes with this:
>
> dyld: Library not loaded: libboost_system.dylib
> Referenced from: (path redacted)
> Reason: image not found
The dylib wasn't found and the linker aborts your program.
>
> The .dylibs are found in the same place as the .a files, so they definitely exist. What am I doing wrong?
Maybe you messed up "dynamic" with "static" versions of the libs.
I would first clear the library search path to boost libs in Xcode's build settings, and also clear a possibly existing linker option in "Other Linker Flags" which specifies linking against any boost library.
Then, decide which kind of library you want to include - *either* static or dynamic versions. Don't mix them! The static versions have an extension "a", the dynamic versions have an extension "dylib". Use the "Link Binary With Libraries" in the "Build Phases" panel to link against the libraries. Please use this method, and don't try to setup build settings manually unless you know how (which may require a number of steps). Remove any libraries from the list which are not needed.
From my experience, Xcode does not require an explicitly mentioned library path in the build settings in order to find those libraries added by the method above. If Xcode did automatically add a library search path while you performed this step, you may optionally delete it again (especially, if you change the library, or change the location of the libraries folder, Xcode doesn't remove the old path and you end up with a mess).
Note:
Building the boost libraries for Mac OS X with all the options and as a fat binary for more than one architecture may be tricky. You could use MacPorts to install boost. And, well I think you know already that only a few boost libs require to link against libraries. Most of boost is header only in which case you just need to set the header search path in your project.
Hope this helps!
Andreas _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden