1

I'm trying to build boost (1.65) on linux with C++11 support to link with my other project (also compiled with C++11 support).

However, I get this kind of error (which seems to happen because my boost is not compiled with c++11):

undefined reference to `boost::filesystem::detail::current_path(boost::system::error_code*)'
data_parser.cc:(.text+0xf15): undefined reference to `boost::filesystem::absolute(boost::filesystem::path const&, boost::filesystem::path const&)'
data_parser.cc:(.text+0x142e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
data_parser.cc:(.text+0x1790): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'

Here is my command line:

./b2 --prefix=boost-install --with-filesystem --with-system --with-program_options --with-thread link=static variant=release cxxflags='-std=c++11' install

But I noticed during compilation if I compile without any --with- (so with all libraries), I can see this line:

- C++11 mutex              : yes

and some other lines related to c++11, however as soon as I add a --with- (e.g. --with-thread), all lines relative to c++11 disappear.

I also tried to add #define BOOST_NO_CXX11_SCOPED_ENUMS around #include <boost/filesystem.hpp> but it doesn't change anything.

I have no clue what is going on here, if someone can help me.

Thank you.

Update: Here is the command of the linking command:

/usr/bin/c++   -std=c++11 -O3 -DNDEBUG   CMakeFiles/MyProject.dir/MyProject.cc.o  -o MyProject  -L/home/whiteshadow/code/MyProject-build/deps/boost-install/lib  -L/home/whiteshadow/code/MyProject-build/deps/zlib-install/lib  -L/home/whiteshadow/code/MyProject-build/deps/nifticlib-install/lib -Wl,-rpath,/home/whiteshadow/code/MyProject-build/deps/boost-install/lib:/home/whiteshadow/code/MyProject-build/deps/zlib-install/lib:/home/whiteshadow/code/MyProject-build/deps/nifticlib-install/lib: -rdynamic ../deps/zlib-install/lib/libz.a ../deps/nifticlib-install/lib/libznz.a ../deps/nifticlib-install/lib/libnifticdf.a ../deps/nifticlib-install/lib/libniftiio.a -lboost_filesystem -lboost_system -lboost_thread -lboost_program_options DataStructure/libDataStructure.a FileHandler/libFileHandler.a Parser/libParser.a Tools/libTools.a -lpthread FileHandler/libFileHandler.a FileHandler/libFileHandler.a Tools/libTools.a DataStructure/libDataStructure.a 

I don't think it comes from a mis-linking issue, because if I remove -lboost_filesystem I have much more linking errors. Here I only have 7, related to only 3 functions (boost::filesystem::detail::status, boost::filesystem::detail::current_path and boost::filesystem::absolute).

Also, in libboost_filesystem.a, I'm able to find symbols for these 3 functions:

(boost::filesystem::detail::status)

00000000000026d0 T _ZN5boost10filesystem6detail6statusERKNS0_4pathEPNS_6system1‌​0error_codeE

(boost::filesystem::detail::current_path)

0000000000000c90 T _ZN5boost10filesystem6detail12current_pathEPNS_6system10error_codeE

(boost::filesystem::absolute)

0000000000001100 T _ZN5boost10filesystem8absoluteERKNS0_4pathES3_
whiteShadow
  • 369
  • 4
  • 19
  • Are you seeing the undefined reference error while building boost or while trying to build your project? And how did you conclude those linker errors have anything to do with C++11? – Praetorian May 04 '17 at 05:18
  • I see these errors while linking boost to my project. I googled the errors and found this thread: [link](http://stackoverflow.com/questions/15634114/cant-link-program-using-boost-filesystem) but the solutions proposed didn't work for me. – whiteShadow May 04 '17 at 05:23
  • 1
    Please update your question with the linker command line which causes the error above. You're mostly likely missing one or both of `-L/path/to/boost/libs -lboost_filesystem`. You may also need to link to `boost_system` – Praetorian May 04 '17 at 05:30
  • I'm pretty sure I include the lib directory and the -lboost_filesystem. Here is a short version of my linking command: -L/home/whiteshadow/code/MyProject-build/deps/boost-install/lib -lboost_filesystem -lboost_system -lboost_thread -lboost_program_options -lpthread – whiteShadow May 04 '17 at 05:34
  • I don't think it's a missing library at linking issue, because I only have 7 linking errors related to filesystem, if I wasn't linking it properly I would have much more. Also, in these 7 errors, it only concerns 3 functions (boost::filesystem::detail::status, boost::filesystem::detail::current_path and boost::filesystem::absolute). – whiteShadow May 04 '17 at 05:39
  • I checked in the libboost_filesystem.a and I found the reference to boost::filesystem::detail::status (00000000000026d0 T _ZN5boost10filesystem6detail6statusERKNS0_4pathEPNS_6system10error_codeE) as well as for current_path and absolute functions, so I don't understand why it is 'undefined'. – whiteShadow May 04 '17 at 06:00
  • Time to create a [mcve]. Use a few of those functions in your test code and see if you can reproduce the error. – Praetorian May 04 '17 at 06:15
  • I tested with a simple program, calling the same function as my code, linked to the same boost library, and it compiles properly (with almost the same command). – whiteShadow May 04 '17 at 06:39
  • The order of libraries on the command line must be as follows. `a-library-that-uses-boost-filesystem.a -lboost-filesystem`. Not the other way around. – n. m. could be an AI May 04 '17 at 06:53
  • Yes, I just realized I was linking boost after some libraries using it. I always forget that order matters. Is it not possible to make a system that looks for previously loaded symbols when linking? That would be so much easier. Anyway, thank you so much. – whiteShadow May 04 '17 at 06:54
  • Use `-Wl,--start-group -lfoo -lbar ... -Wl,--end-group` – Praetorian May 04 '17 at 06:57

0 Answers0