I am building a shared library, which is statically linked against boost as below:
/usr/bin/c++ -fPIC -Wall -Wshadow -g -Wl,-Bstatic -lboost_date_time -lboost_thread -lboost_filesystem -lboost_system -Wl,-Bdynamic -ldl -shared -Wl,-soname,liboms_rocketmq.so -o ../lib/liboms_rocketmq.so
The problem is when dlopen this library on Ubuntu 16.04, symbols that should have been statically linked are undefined(See the following command output: U) whist the symbol could be found in text area of libboost_system.so as is verified in the last command output.
For example:
nm ../liboms_rocketmq.so | grep _ZN5boost6system16generic_categoryEv U _ZN5boost6system16generic_categoryEv
nm /usr/local/lib/libboost_system.so| grep _ZN5boost6system16generic_categoryEv 00000000000013e0 T _ZN5boost6system16generic_categoryEv
Any idea why static linking does not work as expected? aka, inserting the symbol into text area of our shared library.
Figured out the problem: we need to put these depended static libraries at the end, (after our own code) just before -pthreads which should be the last link flag.