C++ – link error when using boost library on MacOSX

boostcmacos

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?

Best Answer

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.

Related Topic