0

When I'm linking program_options to my shared library with:

g++ -L/path_to_static_boost_libs -shared -o "test.so"  ./test.o   -lboost_program_options

I can't load library because of undefined reference on abstract_variables_map::operator[]:

0009b9f8 W int const& boost::program_options::variable_value::as<int>() const
         U boost::program_options::abstract_variables_map::operator[](std::string const&) const
0009b55e W boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast> >::clone() const

I tried to build another program (not shared library) with program_options library linked statically and didn't get undefined reference.

Why I get undefined reference when I'm linking shared library?

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Raman
  • 104
  • 2
  • 8

1 Answers1

1

Step 1: find out mangled name of the unresolved symbol (should already show up in the dlerror() error message).

Step 2: find out which of the boost libraries provides definition for that symbol:

nm -A /path_to_static_boost_libs/*.a | grep <mangled-symbol-name>

Step 3: add that library to the link line of test.so.

Step 4: profit.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362