升级后 g++ 和 boost 链接器出现错误

升级后 g++ 和 boost 链接器出现错误

我遇到了以下问题。我确定这是一个未正确安装/升级的软件包,但我不确定是哪一个:

$ make
g++ -I/usr/include/boost -MM ./YYY.cc ./main.cc ./myClass.cc > buildfiles.d
g++ -Wno-deprecated -Wall -ansi -O2 -I/usr/include/boost   -c -o YYY.o YYY.cc
g++ -Wno-deprecated -Wall -ansi -O2 -I/usr/include/boost   -c -o main.o main.cc
g++ -Wno-deprecated -Wall -ansi -O2 -I/usr/include/boost   -c -o myClass.o myClass.cc
g++ -o prog -Wno-deprecated -Wall -ansi -O2 -I/usr/include/boost -L/usr/lib -lstdc++ -lboost_program_options -lboost_thread ./YYY.o ./main.o ./myClass.o
./YYY.o: In function `void boost::call_once<void (*)()>(boost::once_flag&, void (*)())':
YYY.cc:(.text._ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_[void boost::call_once<void (*)()>(boost::once_flag&, void (*)())]+0x14): undefined reference to `boost::detail::get_once_per_thread_epoch()'
YYY.cc:(.text._ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_[void boost::call_once<void (*)()>(boost::once_flag&, void (*)())]+0x2c): undefined reference to `boost::detail::once_epoch_mutex'
YYY.cc:(.text._ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_[void boost::call_once<void (*)()>(boost::once_flag&, void (*)())]+0x62): undefined reference to `boost::detail::once_epoch_mutex'
YYY.cc:(.text._ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_[void boost::call_once<void (*)()>(boost::once_flag&, void (*)())]+0x67): undefined reference to `boost::detail::once_epoch_cv'
YYY.cc:(.text._ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_[void boost::call_once<void (*)()>(boost::once_flag&, void (*)())]+0x95): undefined reference to `boost::detail::once_epoch_mutex'
[...]

只需明确一点,标题已安装并包含在.h 文件中。

答案1

解决方案涉及更改链接顺序,如手册页所述。问题是,它曾经与旧版本的 g++ 配合良好……

$ make
g++ -I/usr/include/boost -MM ./YYY.cc ./main.cc ./myClass.cc > buildfiles.d
g++ -ansi -O2 -Wall -I/usr/include/boost   -c -o main.o main.cc
g++ -ansi -O2 -Wall -I/usr/include/boost   -c -o myClass.o myClass.cc
g++ -o prog -ansi -O2 -Wall -I/usr/include/boost  ./YYY.o ./main.o ./myClass.o -lstdc++ -L/usr/lib -lboost_program_options -lboost_thread 

相关内容