我使用的是具有GCC 4.6的Ubuntu 12.04,但我的项目需要C ++ 11,因此我使用https://askubuntu.com/a/271561安装4.8,一切似乎都有效,我可以编译我的代码。< / p>
$ g++ --version
g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
我还从网页下载了boost 1.55并使用它构建了它。
./bootstrap.sh
./b2
sudo ./b2 install
一切正常,它似乎是为gcc 4.8而构建的。但是当我尝试链接我的项目时,我得到链接器错误以提升:
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
我首先使用旧版本构建了boost,但在看到这可能与正在使用的不同编译器版本有关后,我删除了boost文件夹,再次提取源并从头开始构建所有内容,重建我的代码但我仍然得到了同样的错误。
更新: 这是我得到的结果&#39; VERBOSE = 1 make&#39;,我使用CMake来构建项目。
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
更新:
从apt-get中删除boost 1.46后我得到了这个错误
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'
似乎应该通过链接器标志中已包含的-lrt标志来解决。
答案 0 :(得分:1)
将-lrt
添加到链接行的末尾以解决问题w / clock_gettime()