1

I am getting static link errors to boost's non header only library. Let's solve it together:

The final binary is supposed to be built using libraries(libbasemainif.a for example) separately built as the higher layers. One of those layers, uses boost::filesystem.

Have a look at the simplified vesrion of g++ command:

g++  /mylis/1.a    /mylibs/2.a   
-L/myboost/Linux-x86_64/lib64 
-Wl,-rpath,/myboost/Linux-x86_64/lib64   -Wl,-Bstatic  
-lboost_thread-mt  -lboost_system-mt  -lboost_filesystem-mt -lboost_date_time-mt
-Wl,-Bdynamic 
-Wl,-rpath,/myinstall/usr/local/lib64 -L/myinstall/usr/local/lib64 -Wl,
-Bstatic -lmyblahblah-static -Wl,-Bdynamic **-lbasemainif** -lbaseif -ldl -rdynamic -lz -lrt 
-L/mypackage1/Linux-x86_64/debug/lib -L /mypackage2/18.1/Linux-x86_64/debug/lib -lpthread -Wl,-rpath,$ORIGIN/../lib64

and this is the error :

/blahblah/lib/libbasemainif.a(errorreportfile.o): 
In function `boost::filesystem3::remove(boost::filesystem3::path const&, boost::system::error_code&)':

/myboost/Linux-x86_64/include/boost/filesystem/v3/operations.hpp:411:
undefined reference to boost::filesystem3::detail::remove(boost::filesystem3::path const&, boost::system::error_code*)'
collect2: ld returned 1 exit status
  • If I remove -Wl,-Bstatic the g++ command executes successfully.But this is not an option in production.
  • The libboost_filesystem.a is available. And all of the laibraries in every layer used boost from the same location.

Can you please tell me why I am getting this error? Thank you

rahman
  • 4,820
  • 16
  • 52
  • 86
  • seems like there is call to detail::remove with last argument as boost::system::error_code*, but the definition is not provided for same causing undefined reference. boost::filesystem3::remove must be a overloaded function and there seems to be definition present for only one of them having boost::system::error_code& as last parameter. Try to provide second definition,. – rahul.deshmukhpatil Dec 15 '15 at 19:01

1 Answers1

2

You should pass to gcc library that implements function after the piece which references it. Something like: -lbasemainif -lboost_filesystem-mt. This is how gcc linker resolves dependencies.

Here is great detailed explanation.

Community
  • 1
  • 1
dewaffled
  • 2,850
  • 2
  • 17
  • 30