0

I have already read a lot of post, but I cannot understand how to compile boost library on OS X 10.9.4 in order to link it statically in my application.

I have Xcode 5 installed and also "Command Line Tools" installed.

I have download the ZIP archive of boost 1.56.0, bootstrapped with:

./bootstrap.sh --prefix=/Users/foo/dev/lib/boost_1_56_0 --libdir=/Users/foo/dev/lib/boost_1_56_0/lib

Then installed with

./b2

But when I tried to compile a little test like the following:

#include <boost/log/trivial.hpp>

int main(int, char*[])
{
    BOOST_LOG_TRIVIAL(trace) << "A trace severity message";


  return 0;
}

With:

clang logtest.cpp -I /Users/foo/lib/boost_1_56_0/include -L /Users/foo/lib/boost_1_56_0/lib

I got a lot of errors regarding the linking:

Undefined symbols for architecture x86_64: 
"boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
  boost::log::v2s_mt_posix::record::reset() in logtest-d5345b.o
...

So I also tried to add the following parameters in the bootstrap:

cxxflags="-arch i386 -arch x86_64" address-model=32_64 threading=multi macos-version=10.9 stage

And the following to b2:

threading=multi link=static runtime-link=static cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"

But nothing changed...

So I'm looking for a guide that teach how I can compile from scratch the boost library and how I can compile an application that links it.

Kill KRT
  • 1,101
  • 2
  • 17
  • 37

2 Answers2

2

In your build command you specified link directory, but didn't specify library you link your executable with. Add -llibrary-name to the command. I believe it should be

clang logtest.cpp -I /Users/foo/lib/boost_1_56_0/include -L /Users/foo/lib/boost_1_56_0/lib -lboost_log

Maybe, add other libraries boost_log depends on (boost_log_setup and pthread are good candidates).

For more information about linking boost libraries, refer to the boost documentation.

Alexey Shmalko
  • 3,678
  • 1
  • 19
  • 35
  • Yes, for sure I was forgetting to specify the libraries name to be linked with, but anyway I still have the same problem with the following command: c++ logTest.cpp -I ../boost_1_56_0/include/ -L ../boost_1_56_0/lib/ -lboost_system -lboost_thread -lboost_log -lboost_log_setup -lpthread (I have also tried on OS X 10.10 with Xcode 6, no GCC installed) – Kill KRT Aug 25 '14 at 19:51
0

I can provide you the example of code from my CMakeLists on Mac Os. It was used exactly for linking of boost logging library:

target_link_libraries(testq boost_system boost_thread boost_log boost_log_setup pthread)
Alex WW
  • 1
  • 1
  • Just as curiosity, how/where did you find the list of libraries to be linked with? Anyway, as you can see in my comment for Alex's answer, I still have problem with the linking process. – Kill KRT Aug 25 '14 at 19:57