dutt
dutt

Reputation: 8209

Linker error with Boost, referenced in discarded section

I'm using Ubuntu 12.04 which have GCC 4.6, but I need C++11 for my project so I used https://askubuntu.com/a/271561 to install 4.8 and everything seem to work, I can compile my code.

$ g++ --version
g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

I also downloaded boost 1.55 from the web page and built it using.

./bootstrap.sh
./b2
sudo ./b2 install

And everything works, it seems to build for gcc 4.8. But when I try to link my project I get linker errors to boost:

Linking CXX executable server
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_12bad_weak_ptrEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_12bad_weak_ptrEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_12bad_weak_ptrEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_12bad_weak_ptrEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_12bad_weak_ptrEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED1Ev[_ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED1Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libboost_thread-mt.a(thread.o)
collect2: error: ld returned 1 exit status

I first built boost with the old version, but after seeing that this could relate to different compiler versions being used I removed the boost folder, extracted the source again and built everything from scratch, rebuilt my code too but I still get the same error.

UPDATE: Here's what I get from 'VERBOSE=1 make', I'm using CMake to build the project.

Linking CXX executable server
cd <path>/build/server && /usr/bin/cmake -E cmake_link_script CMakeFiles/server.dir/link.txt --verbose=1
/usr/bin/c++   -g -O0 -Wall -fno-inline -ftest-coverage -fprofile-arcs -D__GLIBCXX_DEBUG     --coverage -lrt -fno-use-linker-plugin CMakeFiles/server.dir/main.cpp.o  -o server -rdynamic ../core/libcore.a -Wl,-Bstatic -lboost_date_time-mt -Wl,-Bdynamic /usr/local/lib/libboost_log.a -Wl,-Bstatic -lboost_filesystem-mt -lboost_thread-mt -Wl,-Bdynamic -lpthread -Wl,-Bstatic -lboost_system-mt -Wl,-Bdynamic /usr/local/lib/libboost_unit_test_framework.a -lpthread ../messages/libmessages.a -Wl,-Bstatic -lboost_date_time-mt -Wl,-Bdynamic /usr/local/lib/libboost_log.a -Wl,-Bstatic -lboost_filesystem-mt -lboost_thread-mt -Wl,-Bdynamic -lpthread -Wl,-Bstatic -lboost_system-mt -Wl,-Bdynamic /usr/local/lib/libboost_unit_test_framework.a -lprotobuf

UPDATE:

After removing boost 1.46 from apt-get I get this error instead

Linking CXX executable server
/usr/local/lib/libboost_thread.a(thread.o): In function `boost::this_thread::hiden::sleep_for(timespec const&)':
thread.cpp:(.text+0x1290): undefined reference to `clock_gettime'

Which it seems should be solved by the -lrt flag which is already included in the linker flags.

Upvotes: 1

Views: 1870

Answers (1)

user3159253
user3159253

Reputation: 17455

add -lrt to the end of the link line to resolve the problem w/ clock_gettime()

Upvotes: 1

Related Questions