与升压波链接时链接器“未定义引用”错误

问题描述 投票:0回答:1

我正在尝试将我的程序(gcc)与boost 1.70(特别是Wave)链接起来,并收到链接器错误(“未定义引用”)。

我正在使用带有加号BOOST_WAVE_SUPPORT_THREADING=0的以下命令将boost编译到静态库中(因为在我的情况下不需要线程支持。

./b2 -j 8 toolset=gcc-7.2.0 cxxstd=17 link=static threading=multi runtime-link=static address-model=32 variant=release --without-python --stagedir=./linux/release stage

编译通过(少量警告)。

现在,我正在构建另一个静态库(使用wave)。与以前相同,编译器和std是c ++ 17。这也成功建立。第三部分是实际的可执行文件,它链接到先前的静态库,然后链接到boost wave(实际上是system,wave,文件系统和regex)。编译也是用std = 17进行的(与std = c ++ 11 btw的结果相同)。错误发生在boost的链接阶段,给出以下错误:

MyParserImplementation.cpp:(.text._ZN5boost4wave4impl19pp_iterator_functorINS0_7contextIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS0_8cpplexer12lex_iteratorINSE_9lex_tokenINS0_4util13file_positionINSH_11flex_stringIcSA_SB_NSH_9CowStringINSH_22AllocatorStringStorageIcSB_EES6_EEEEEEEEEENS0_26iteration_context_policies19load_file_to_stringE28advanced_preprocessing_hooksNS0_9this_typeEEEE12pp_directiveEv[_ZN5boost4wave4impl19pp_iterator_functorINS0_7contextIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEENS0_8cpplexer12lex_iteratorINSE_9lex_tokenINS0_4util13file_positionINSH_11flex_stringIcSA_SB_NSH_9CowStringINSH_22AllocatorStringStorageIcSB_EES6_EEEEEEEEEENS0_26iteration_context_policies19load_file_to_stringE28advanced_preprocessing_hooksNS0_9this_typeEEEE12pp_directiveEv]+0x301): undefined reference to `boost::wave::grammars::cpp_grammar_gen<boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > >, std::__cxx11::list<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >, boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >, boost::default_user_allocator_new_delete, std::mutex, 32u, 0u> > >::parse_cpp_grammar(boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > > const&, boost::wave::cpplexer::lex_iterator<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > > > const&, boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > const&, bool&, boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >&, std::__cxx11::list<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >, boost::fast_pool_allocator<boost::wave::cpplexer::lex_token<boost::wave::util::file_position<boost::wave::util::flex_string<char, std::char_traits<char>, std::allocator<char>, boost::wave::util::CowString<boost::wave::util::AllocatorStringStorage<char, std::allocator<char> >, char*> > > >, boost::default_user_allocator_new_delete, std::mutex, 32u, 0u> >&)'
collect2: error: ld returned 1 exit status

(部分输出)

[如前所述,我已经使用std=c++11和gcc 7.3.0进行了相同的尝试,该版本已通过boost(针对其版本,在其网站上进行了测试)正式测试,结果相同。还值得一提的是,在构建库和可执行文件的调试版本时,一切正常。

编辑:这是链接命令:

g++ -O3 -DNDEBUG -std=c++17 -I /path/to/static/lib/myparser -I /path/to/boost/1_70_0 -lstdc++ -o bin/my_release/exe \
-L /path/to/static/lib/myparser/release -lmyparser -L /path/to/boost/1_70_0/linux/release/lib \
   -l boost_system \
   -l boost_wave \
   -l boost_filesystem \
   -l boost_regex \

知道有什么问题吗?

c++ boost
1个回答
0
投票

只是偶然看到的-我今天遇到了类似的问题。问题是BOOST_WAVE_SUPPORT_THREADING=0间接导致快速池分配器使用内部null_mutex而不是std::mutex。解决方法是确保使用相同的BOOST_WAVE_SUPPORT_THREADING=0构建可执行文件,并且应该使用null_mutex版本。

© www.soinside.com 2019 - 2024. All rights reserved.