无法编译boost :: fiber官方示例

时间:2017-10-01 17:50:42

标签: c++ boost fiber

我正在尝试使用boost :: fiber库,但我无法使用boost光纤编译代码。因此我转而编译并运行boost官方示例。我安装了最新版本的boost库1.65.1,安装似乎没问题。我执行了以下命令来编译simple.cpp

g++ -I /usr/local/include/boost/ -L /usr/local/lib/ -lboost_fiber -std=c++11 libs/fiber/examples/simple.cpp    

但我得到以下抱怨:

/tmp/ccWQ5ZMf.o: In function `main':
simple.cpp:(.text+0x7b): undefined reference to `boost::fibers::fiber::join()'
/tmp/ccWQ5ZMf.o: In function `boost::context::continuation::~continuation()':
simple.cpp:(.text._ZN5boost7context12continuationD2Ev[_ZN5boost7context12continuationD5Ev]+0x59): undefined reference to `ontop_fcontext'
/tmp/ccWQ5ZMf.o: In function `boost::context::continuation::resume()':
simple.cpp:(.text._ZN5boost7context12continuation6resumeEv[_ZN5boost7context12continuation6resumeEv]+0x68): undefined reference to `jump_fcontext'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::context::context(unsigned long, boost::fibers::type, boost::fibers::launch)':
simple.cpp:(.text._ZN5boost6fibers7contextC2EmNS0_4typeENS0_6launchE[_ZN5boost6fibers7contextC5EmNS0_4typeENS0_6launchE]+0x18): undefined reference to `vtable for boost::fibers::context'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::fiber::get_id() const':
simple.cpp:(.text._ZNK5boost6fibers5fiber6get_idEv[_ZNK5boost6fibers5fiber6get_idEv]+0x3b): undefined reference to `boost::fibers::context::get_id() const'
/tmp/ccWQ5ZMf.o: In function `boost::this_fiber::yield()':
simple.cpp:(.text._ZN5boost10this_fiber5yieldEv[_ZN5boost10this_fiber5yieldEv]+0x5): undefined reference to `boost::fibers::context::active()'
simple.cpp:(.text._ZN5boost10this_fiber5yieldEv[_ZN5boost10this_fiber5yieldEv]+0xd): undefined reference to `boost::fibers::context::yield()'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::fiber::fiber<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int, void, void, void>(void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int)':
simple.cpp:(.text._ZN5boost6fibers5fiberC2IRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEvvvEEOT_DpT0_[_ZN5boost6fibers5fiberC5IRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEvvvEEOT_DpT0_]+0x2c): undefined reference to `boost::context::stack_traits::default_size()'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::fiber::fiber<boost::context::basic_fixedsize_stack<boost::context::stack_traits>, void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>(boost::fibers::launch, std::allocator_arg_t, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int)':
simple.cpp:(.text._ZN5boost6fibers5fiberC2INS_7context21basic_fixedsize_stackINS3_12stack_traitsEEERFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEENS0_6launchESt15allocator_arg_tT_OT0_DpT1_[_ZN5boost6fibers5fiberC5INS_7context21basic_fixedsize_stackINS3_12stack_traitsEEERFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEENS0_6launchESt15allocator_arg_tT_OT0_DpT1_]+0x7f): undefined reference to `boost::fibers::fiber::start_()'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::worker_context<boost::context::basic_fixedsize_stack<boost::context::stack_traits> >(boost::fibers::launch, boost::context::preallocated const&, boost::context::basic_fixedsize_stack<boost::context::stack_traits> const&, void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int)':
simple.cpp:(.text._ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEC2INS_7context21basic_fixedsize_stackINSG_12stack_traitsEEEEENS0_6launchERKNSG_12preallocatedERKT_SB_SD_i[_ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEC5INS_7context21basic_fixedsize_stackINSG_12stack_traitsEEEEENS0_6launchERKNSG_12preallocatedERKT_SB_SD_i]+0x15d): undefined reference to `boost::fibers::context::~context()'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::run_(boost::context::continuation&&)':
simple.cpp:(.text._ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEE4run_EONS_7context12continuationE[_ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEE4run_EONS_7context12continuationE]+0xb5): undefined reference to `boost::fibers::context::terminate()'
/tmp/ccWQ5ZMf.o: In function `void* boost::context::detail::create_context2<boost::context::detail::record<boost::context::continuation, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<std::_Mem_fn<boost::context::continuation (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::*)(boost::context::continuation&&)> (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>*, std::_Placeholder<1>)> >, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<std::_Mem_fn<boost::context::continuation (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::*)(boost::context::continuation&&)> (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>*, std::_Placeholder<1>)> >(boost::context::preallocated, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<std::_Mem_fn<boost::context::continuation (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::*)(boost::context::continuation&&)> (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>*, std::_Placeholder<1>)>&&)':
simple.cpp:(.text._ZN5boost7context6detail15create_context2INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEES7_SX_EEPvNS0_12preallocatedET0_OT1_[_ZN5boost7context6detail15create_context2INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEES7_SX_EEPvNS0_12preallocatedET0_OT1_]+0xd8): undefined reference to `make_fcontext'
simple.cpp:(.text._ZN5boost7context6detail15create_context2INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEES7_SX_EEPvNS0_12preallocatedET0_OT1_[_ZN5boost7context6detail15create_context2INS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEES7_SX_EEPvNS0_12preallocatedET0_OT1_]+0x10f): undefined reference to `jump_fcontext'
/tmp/ccWQ5ZMf.o: In function `void boost::context::detail::context_entry<boost::context::detail::record<boost::context::continuation, boost::context::basic_fixedsize_stack<boost::context::stack_traits>, std::_Bind<std::_Mem_fn<boost::context::continuation (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::*)(boost::context::continuation&&)> (boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>*, std::_Placeholder<1>)> > >(boost::context::detail::transfer_t)':
simple.cpp:(.text._ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE[_ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE]+0x70): undefined reference to `jump_fcontext'
simple.cpp:(.text._ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE[_ZN5boost7context6detail13context_entryINS1_6recordINS0_12continuationENS0_21basic_fixedsize_stackINS0_12stack_traitsEEESt5_BindIFSt7_Mem_fnIMNS_6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEEFS4_OS4_EEPSO_St12_PlaceholderILi1EEEEEEEEvNS1_10transfer_tE]+0xc9): undefined reference to `ontop_fcontext'
/tmp/ccWQ5ZMf.o: In function `boost::fibers::worker_context<void (&)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int), char const*, int>::~worker_context()':
simple.cpp:(.text._ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEED2Ev[_ZN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEED5Ev]+0x20): undefined reference to `boost::fibers::context::~context()'
/tmp/ccWQ5ZMf.o:(.rodata._ZTIN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEE[_ZTIN5boost6fibers14worker_contextIRFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiEJPKciEEE]+0x10): undefined reference to `typeinfo for boost::fibers::context'
collect2: error: ld returned 1 exit status

有人可以帮我解决这个问题吗? 提前致谢

1 个答案:

答案 0 :(得分:2)

应在源/目标文件之后指定库(-l)。指定-l的最佳位置在命令的末尾。

boost_fiber取决于boost_context

所以你在命令行的末尾需要-lboost_fiber -lboost_context