c++ - 与升压波链接时出现链接器“未定义的引用”错误
问题描述
我正在尝试将我的程序(gcc)与 boost 1.70(特别是 Wave)链接,并出现链接器错误(“未定义的引用”)。
我正在使用带有附加标志的以下命令将 boost 编译到静态库中BOOST_WAVE_SUPPORT_THREADING=0
(因为在我的情况下不需要线程支持)。
./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)。与以前相同的编译器和标准是 c++17。这一个也成功构建。第三部分是实际的可执行文件,它链接到前面的静态库,然后链接到 boost wave(实际上是系统、wave、文件系统和正则表达式)。编译也使用 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 和 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
版本。
推荐阅读
- vue.js - 禁用特定文件上的特定 Vue 警告
- javascript - JS 相当于这个 PHP 值?
- javascript - reactJS useState hook 实际值在异步承诺中已过时
- python - 如何修改 yarl.URL 对象?
- javascript - Javascript DOM OffsetWidth 是否在不同设备上有所不同?
- swift - Swift - 从 UIView 获取随机 CGPoints
- c# - 称重秤条码阅读器 C#
- list - 列出 svn remore repo 的目录(和子目录)
- oracle - 立即对名称中包含数字的表执行
- google-cloud-platform - 正在修复的 GCP MIG 实例