n179911
n179911

Reputation: 20291

link error when using boost library on MacOSX

I have created a XCode project and I have added "/opt/local/include/boost" to Header Search Path and "/opt/local/lib" to Library Search Path

But I still have this error:

boost::system::get_generic_category()", referenced from:
   __static_initialization_and_destruction_0(int, int)in main.o
   __static_initialization_and_destruction_0(int, int)in main.o
   __static_initialization_and_destruction_0(int, int)in main.o

And in my /opt/local/lib, I find this (I assume that is Boost.System library):

-rw-r--r--  2 root  admin     80600 Jul 23 16:31 libboost_system-mt.a
-rwxr-xr-x  2 root  admin     30988 Jul 23 16:30 libboost_system-mt.dylib*

Can you please tell me what am I missing?

Upvotes: 2

Views: 4606

Answers (3)

haysclark
haysclark

Reputation: 1080

Updated: For XCode 4 you'll need to add the .dylib files for the linker. In XCode use the 'Project Navigator' option in the 'Navigator' pane. Then click on your project, then click on your target, then pick the 'Build Phases' tab, and press the "+" button in the 'Link Binary With Libraries' group. You'll need to add whatever libboost_ .dylib your trying to utilize.

Adding Link Binary in XCode4 for Boost

Upvotes: 3

Wgaffa
Wgaffa

Reputation: 622

To link to Libraries in XCode, right click the "Target" that uses Boost and choose Get Info. In the lower list "Linked Libraries" add the boost dylib files by clicking the +

Hope this helped.

Upvotes: 2

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 247899

Adding the library path isn't sufficient. That just ensures that whenever you tell it to link to a library, it will search for that library in the specified path as well as all the default paths.

So you also need to actually tell the compiler to link to the library, with the flag

-lboost_system-mt

On Windows, Boost supports autolinking by default -- that is, if you just include the correct headers, it will attempt to link to the actual libraries as well (through use of a MSVC #pragma). On other platforms, you have to manually link to the library.

Upvotes: 5

Related Questions