不寻常的c++链接错误-“定义在丢弃部分”

时间:2022-11-07 13:48:31

I am attempting to link my program executable, but I keep getting errors.

我正在尝试连接我的程序可执行文件,但我不断收到错误。

Having

boost::this_thread::sleep(boost::posix_time::milliseconds(10));

in my source code yields the following error in the linker:

在我的源代码中,链接器中产生以下错误:

`.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<std::runtime_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month>::~error_info_injector()]' of /usr/local/lib/libboost_thread.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/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_year>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_month>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)

Using boost::thread::condition_variable::wait yields

使用boost::线程::condition_variable::等待收益率

src/net/libnet.a(semaphore.cpp.o): In function `interruption_checker':
/usr/local/include/boost/thread/pthread/thread_data.hpp:96: undefined reference to `boost::detail::get_current_thread_data()'
src/net/libnet.a(semaphore.cpp.o): In function `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/local/include/boost/thread/pthread/condition_variable.hpp:57: undefined reference to `boost::this_thread::interruption_point()'
collect2: ld returned 1 exit status

I am using CMake, and it tells me Make issues the following command, which fails:

我正在使用CMake,它告诉我发出以下命令,但失败了:

    /usr/bin/c++       CMakeFiles/rcon.dir/src/main.cpp.o  -o rcon -rdynamic -L/usr/local/lib /usr/local/lib/libboost_system.a /usr/local/lib/libboost_thread.a -lpthread src/net/libnet.a src/log/liblogging.a -Wl,-rpath,/usr/local/lib 

Whatever could be wrong? It is linking in libboost_thread.a?

Update

更新

After moving libnet and liblogging (parts of my program, compiled into static libraries because I thought it was neat) before the boost libraries in the command line removes the undefined errors. However, now I get these when compiling with boost::condition_variable in my code, while the other error is unchanged:

在命令行中的boost库删除未定义的错误之前,将libnet和liblog(我的程序的一部分,因为我认为它很好而编译为静态库)移动之后。但是,现在我在代码中使用boost: condition_variable编译时得到了这些错误,而另一个错误没有改变:

`.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::lock_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_10lock_errorEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<std::runtime_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month>::~error_info_injector()]' of /usr/local/lib/libboost_thread.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/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::thread_resource_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_21thread_resource_errorEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::condition_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::condition_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15condition_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::condition_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_15condition_errorEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_year>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_month>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian9bad_monthEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian16bad_day_of_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_month> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian9bad_monthEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_21thread_resource_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_10lock_errorEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)

4 个解决方案

#1


12  

Now I'm a bit embarrassed. Apparently, something was wrong with my boost library. Probably, I compiled it with one version of gcc, after which I did an update all. This probably updated GCC with some form of minor incompatibility between the two versions. I could be completely wrong about that though.

现在我有点尴尬。显然,我的boost库出了问题。可能,我使用了一个版本的gcc来编译它,之后我更新了所有的版本。这可能更新了GCC的两个版本之间的一些不兼容性。我可能完全错了。

I deleted all occurences of boost, and pulled boost from the Archlinux repositories instead, which currently is up to date with the official releases. Now it compiles as it should.

我删除了所有发生的boost,并从Archlinux存储库中提取了boost,这是目前官方发布的最新版本。现在,它按照它应该的方式进行编译。

Silly me. :(

愚蠢的我。:(

#2


6  

Linkonce sections (and the newer notion of comdat groups) are a way for the compiler to emit template instantiations and out-of-line inlined functions without worrying about lots of duplicate copies in the linked output file. There may be a copy of, for instance, an instantiated template function in 2+ discrete object files, of which the linker will pick one and discard all the others. In order for that case to link properly, it's important that each copy defines and references exactly the same set of symbols.

Linkonce区段(以及comdat组的新概念)是编译器发出模板实例化和线外内联函数的一种方式,无需担心链接输出文件中有大量重复的副本。例如,在2+离散对象文件中可能有一个实例化模板函数的副本,其中的链接器将选择一个并丢弃所有其他的。为了使这种情况正确地链接,重要的是每个拷贝定义和引用完全相同的一组符号。

Yet sometimes extra symbols are defined when different compilation options are used (e.g., -g, or when compiler options differ between object files, as is usually the case with shared libraries) or the set of symbols has changed from one version of gcc to the next (I suspect this is unlikely in your case - EDIT: well, colour me excited, looks like that might've been your folly. Glad your problem's solved). What may be happening here is that you have a reference from a non-linkonce section to a symbol that's defined in some (but not all) copies of a particular linkonce section. If the linker happens to discard the one with that symbol and keep the one without that symbol, you get this error.

但有时额外的符号定义当使用不同的编译选项(如- g,或者当编译器选项对象文件之间的不同,通常是共享库的情况)或一组符号改变了从一个版本的gcc到下一个(我觉得这是不太可能在你的情况中,编辑:嗯,颜色我非常兴奋,看起来会一直在你的愚蠢。很高兴你的问题的解决)。这里可能发生的情况是,从一个非链接段到一个符号的引用,该符号在一个特定的链接段的某些(但不是所有)副本中定义。如果链接器碰巧抛弃了这个符号并保留了那个符号,就会得到这个错误。

I would propose you rearrange the link order of your object modules to try to get the linker to keep the section that defines the symbol(s) you need; in particular try to move the object files mentioned in the error message to the end or beginning of the object file list according to their dependencies (remember object files are linked left to right in their command line order).

我建议您重新安排对象模块的链接顺序,以便让链接器保留定义所需符号的部分;特别要尝试根据对象文件的依赖关系将错误消息中提到的对象文件移动到对象文件列表的末尾或开头(请记住,对象文件是按命令行顺序从左到右链接的)。

#3


4  

Here's my actual solution for it that does not involve changing your entire project's build flags:

下面是我的实际解决方案,它不涉及更改整个项目的构建标志:

Assuming you've got this function:

假设你有这个函数:

void foo() {/* ... */}

and your linker yields this error message:

链接器会产生错误信息:

`foo' referenced in section `...' of ...: defined in discarded section `.text' of ...

That means, somewhere in the compilation/linking process the function was removed.

这意味着,在编译/链接过程的某个地方,函数被删除。

You can enforce GCC's __attribute__((used)) function attribute to force the compiler not to garbage-collect the function in any way:

您可以强制执行GCC的__attribute__(已使用)函数属性,以强制编译器不要以任何方式垃圾收集函数:

__attribute__((used)) void foo() {/* ... */}

When used often, I recommend defining a macro (which can also be used to be compatible with other compilers):

如果经常使用,我建议定义一个宏(它也可以与其他编译器兼容):

#define USED __attribute__((used))
//Usage example
USED void foo() {/* ... */}

Note that it is not advisable to add this attribute to all functions - it might increase your executable / library size because many unused functions will not be removed from the final compilate.

注意,不建议将此属性添加到所有函数中——它可能会增加可执行/库大小,因为许多未使用的函数不会从最终编译中删除。

See the function attributes GCC docpage

请参见函数属性GCC docpage

#4


3  

I suspect part or all of the problem is the order of libraries on the link line. Some linkers require you to list libraries from most dependent to least dependent, left to right, so they know which symbols to extract from each library. As a first start, move libnet before libboost_thread and see if things improve (or at least change).

我怀疑部分或全部的问题是图书馆在链接线上的顺序。有些链接器要求您从最依赖的到最不依赖的,从左到右列出库,以便它们知道从每个库中提取哪些符号。首先,在libboost_thread之前移动libnet,看看情况是否有所改善(或至少有所改变)。

#1


12  

Now I'm a bit embarrassed. Apparently, something was wrong with my boost library. Probably, I compiled it with one version of gcc, after which I did an update all. This probably updated GCC with some form of minor incompatibility between the two versions. I could be completely wrong about that though.

现在我有点尴尬。显然,我的boost库出了问题。可能,我使用了一个版本的gcc来编译它,之后我更新了所有的版本。这可能更新了GCC的两个版本之间的一些不兼容性。我可能完全错了。

I deleted all occurences of boost, and pulled boost from the Archlinux repositories instead, which currently is up to date with the official releases. Now it compiles as it should.

我删除了所有发生的boost,并从Archlinux存储库中提取了boost,这是目前官方发布的最新版本。现在,它按照它应该的方式进行编译。

Silly me. :(

愚蠢的我。:(

#2


6  

Linkonce sections (and the newer notion of comdat groups) are a way for the compiler to emit template instantiations and out-of-line inlined functions without worrying about lots of duplicate copies in the linked output file. There may be a copy of, for instance, an instantiated template function in 2+ discrete object files, of which the linker will pick one and discard all the others. In order for that case to link properly, it's important that each copy defines and references exactly the same set of symbols.

Linkonce区段(以及comdat组的新概念)是编译器发出模板实例化和线外内联函数的一种方式,无需担心链接输出文件中有大量重复的副本。例如,在2+离散对象文件中可能有一个实例化模板函数的副本,其中的链接器将选择一个并丢弃所有其他的。为了使这种情况正确地链接,重要的是每个拷贝定义和引用完全相同的一组符号。

Yet sometimes extra symbols are defined when different compilation options are used (e.g., -g, or when compiler options differ between object files, as is usually the case with shared libraries) or the set of symbols has changed from one version of gcc to the next (I suspect this is unlikely in your case - EDIT: well, colour me excited, looks like that might've been your folly. Glad your problem's solved). What may be happening here is that you have a reference from a non-linkonce section to a symbol that's defined in some (but not all) copies of a particular linkonce section. If the linker happens to discard the one with that symbol and keep the one without that symbol, you get this error.

但有时额外的符号定义当使用不同的编译选项(如- g,或者当编译器选项对象文件之间的不同,通常是共享库的情况)或一组符号改变了从一个版本的gcc到下一个(我觉得这是不太可能在你的情况中,编辑:嗯,颜色我非常兴奋,看起来会一直在你的愚蠢。很高兴你的问题的解决)。这里可能发生的情况是,从一个非链接段到一个符号的引用,该符号在一个特定的链接段的某些(但不是所有)副本中定义。如果链接器碰巧抛弃了这个符号并保留了那个符号,就会得到这个错误。

I would propose you rearrange the link order of your object modules to try to get the linker to keep the section that defines the symbol(s) you need; in particular try to move the object files mentioned in the error message to the end or beginning of the object file list according to their dependencies (remember object files are linked left to right in their command line order).

我建议您重新安排对象模块的链接顺序,以便让链接器保留定义所需符号的部分;特别要尝试根据对象文件的依赖关系将错误消息中提到的对象文件移动到对象文件列表的末尾或开头(请记住,对象文件是按命令行顺序从左到右链接的)。

#3


4  

Here's my actual solution for it that does not involve changing your entire project's build flags:

下面是我的实际解决方案,它不涉及更改整个项目的构建标志:

Assuming you've got this function:

假设你有这个函数:

void foo() {/* ... */}

and your linker yields this error message:

链接器会产生错误信息:

`foo' referenced in section `...' of ...: defined in discarded section `.text' of ...

That means, somewhere in the compilation/linking process the function was removed.

这意味着,在编译/链接过程的某个地方,函数被删除。

You can enforce GCC's __attribute__((used)) function attribute to force the compiler not to garbage-collect the function in any way:

您可以强制执行GCC的__attribute__(已使用)函数属性,以强制编译器不要以任何方式垃圾收集函数:

__attribute__((used)) void foo() {/* ... */}

When used often, I recommend defining a macro (which can also be used to be compatible with other compilers):

如果经常使用,我建议定义一个宏(它也可以与其他编译器兼容):

#define USED __attribute__((used))
//Usage example
USED void foo() {/* ... */}

Note that it is not advisable to add this attribute to all functions - it might increase your executable / library size because many unused functions will not be removed from the final compilate.

注意,不建议将此属性添加到所有函数中——它可能会增加可执行/库大小,因为许多未使用的函数不会从最终编译中删除。

See the function attributes GCC docpage

请参见函数属性GCC docpage

#4


3  

I suspect part or all of the problem is the order of libraries on the link line. Some linkers require you to list libraries from most dependent to least dependent, left to right, so they know which symbols to extract from each library. As a first start, move libnet before libboost_thread and see if things improve (or at least change).

我怀疑部分或全部的问题是图书馆在链接线上的顺序。有些链接器要求您从最依赖的到最不依赖的,从左到右列出库,以便它们知道从每个库中提取哪些符号。首先,在libboost_thread之前移动libnet,看看情况是否有所改善(或至少有所改变)。