Reza Toghraee Reza Toghraee - 11 days ago 8x
C++ Question

linking error for boost::program_options

I can't figure out a linking error to use boost::program_options. Here's a sample c++ code:

# sample_code.cpp
#include <boost/program_options.hpp>
int main()
boost::program_options::options_description description("Test");

I've also installed boost 1.57.0 using MacPorts on Yosemite 10.10.2. Here's the related library:


Let's compile and link this code:

alias g++='/opt/local/bin/g++-mp-5 -std=gnu++14 -I/opt/local/include -L/opt/local/lib'

g++ sample_code.cpp -lboost_program_options-mt

And it fails during linking:

Undefined symbols for architecture x86_64:
"boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)"
ld: symbol(s) not found for architecture x86_64

Any thoughts?


As pointed by Petesh in comments above, the issue turns out to be how MacPorts build boost using clang++ and not g++.

Unfortunately, MacPorts does not offer any gcc built variants for boost!