gpt4 book ai didi

c++ - 与 boost 波链接时的链接器 'undefined references'错误

转载 作者:行者123 更新时间:2023-12-02 10:38:36 28 4
gpt4 key购买 nike

我正在尝试将我的程序(gcc)与boost 1.70(特别是Wave)链接起来,并得到链接器错误(“ undefined reference ”)。

我正在使用带有附加标志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 \

知道有什么问题吗?

最佳答案

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

关于c++ - 与 boost 波链接时的链接器 'undefined references'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57056487/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com