Linking to boost

Hello,

The steps below were done after a re-install of XCode (apparently Snow upgrade did not upgrade it properly).

After following the ./bootstrap.sh and bjam install steps,

I have directory like this:

~/Library/boost library/boost_1_400/include
~/Library/boost library/boost_1_400/lib/
libboost_serialization.a
libboost_serialization.dynlib

and have the include directory path to Project > Build > Search path > Header Search Paths and and the lib directory path to Project > Build > Search path > Library Search Paths.

In XCode I did Project > Add to project > libboost_serialization.a

Running under Debug generates this message:

The Debugger has exited with status 0.
Session started at 2009-11-02 19:52:02 -0500.
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys003
Loading program into debugger…
Program loaded.
run
Switching to process 14735
Running…
dyld: Library not loaded: libboost_serialization.dylib
Referenced from: ~/projets/2009/Xcode/myproject/build/Debug/distribution_survival
Reason: image not found
sharedlibrary apply-load-rules all
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Cannot call into the loader at present, it is locked.)
warning: Couldn't find minimal symbol for "_sigtramp" - backtraces may be unreliable
Cannot access memory at address 0x0
Cannot access memory at address 0x0
(gdb)

I use the SDK 10.6, 64 bit Intel architecture, otherwise (32bit) I get a compile, not a runtime error (probably normal because by default bjam creates the libraries using a 64 bit by default).

Even if I remove libboost_serialization.a from the project and put libboost_serialization.dylib in its place, I get the same runtime error.

Some help would be appreciated.

Macbook alum, Mac OS X (10.6.1), XCode 3.1.2

Posted on Nov 2, 2009 5:11 PM

Reply
19 replies

Nov 7, 2009 2:21 PM in response to frangipane

frangipane wrote:
I would like to do that, but as I said, /usr/local is not accessible from XCode > AddToProject, therefore I cannot add the library libboost_serialization.dylib to the project, which as I understand it, is necessary.


OK. I get it now. Sorry about that. You can do ⌘^G to open a dialog where you can type in /usr/local.

Also, Xcode really hacks up gcc to a great extent. I actually had to add '/usr/local/include' into my search paths. I've been giving you misinformation. I don't like that.

For now, I haven't done a custom build anyway, I used the default:

http://www.boost.org/doc/libs/140_0/more/gettingstarted/unix-variants.html#easy-build-and-install

specifying only the --prefix = path and the --with-library_name options


I just did that too. I built a little test using the regex example. I had to add '/usr/local/include' to the search paths (I don't like that - bad Apple bad). Then I added the libboost_regex.a library (via ⌘^G).

I could have also added "-lboost_regex" as a linker option. But since Apple has so helpfully hacked up GCC, I probably would have had to add "-L/usr/local/lib" to the linker options as well.

Plus, the GCC 4.2 compiler in 10.6 is known to have serious bugs


So far I'm not encountering problems except for linking, and I'm happy with GCC 4.0. I'm using a very simple test case for linking.


4.2 is the default compiler in 10.6. In order to run my 6 line boost example (or any C++ program for that matter) I had to select the target, get info, and remove those nasty GLIBCXXDEBUG macros (see this thread for more details).

Now, last and most importantly, when you add "libboost_xxx.a" to a project, that does not give you static linking. Your executable is linked to the dynamic library:

medusa:Debug jdaniel$ otool -L btest
btest:
libboost_regex.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 123.0.0)


Luckily, the shell isn't as hacked up as gcc. I can my "btest" program from the command line because "libboost_regex.dylib" is located in /usr/local/lib.

I hope all of this makes sense. I suspect that your problem is some old executables that are 32-bit that you are trying to link to the 64-bit new ones you just created. You probably have to rebuild everything you have under 10.6 to get the correct architecture.

Nov 7, 2009 2:28 PM in response to frangipane

copy the boost 1_400 directory to /usr/local

build boost from there (5.1. in http://www.boost.org/doc/libs/140_0/more/gettingstarted/unix-variants.html#link-your-program-to-a-boost-library)

and then copy bin.v2 to say ~/Library/boost 1_400

1) Include the latter (or perhaps some directory down the tree) in the library search path
2) Add to project the desired library in this path

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Linking to boost

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.