簡體   English   中英

鏈接器與增強波鏈接時的“未定義引用”錯誤

[英]Linker 'undefined references' errors when linking with boost wave

我正在嘗試將我的程序 (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)。 與以前相同的編譯器和標准是 c++17。 這一個也構建成功。 第三部分是實際的可執行文件,它鏈接到之前的靜態庫,然后鏈接到 boost wave(實際上是 system、wave、filesystem 和 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版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM