简体   繁体   中英

Linker 'undefined references' errors when linking with boost wave

I'm trying to link my program (gcc) with boost 1.70 (Wave specifically) and getting linker errors ("undefined reference").

I'm compiling boost into a static library with the following command with an addition flag BOOST_WAVE_SUPPORT_THREADING=0 (since threads support not needed in my case).

./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

Compilation passes (few warnings).

Now, I'm building another static library (which uses wave). Same compiler and std is c++17 as previously. This one also builds successfully. Third part is the actual executable which is linked to the previous static library and then linked to boost wave (actually system, wave, filesystem and regex). Compilation is also with std=17 (same results with std=c++11 btw). The error occurs at the linking phase of boost giving the following errors:

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

(partial output)

As mentioned before, I've tried the same with std=c++11 and also with gcc 7.3.0 which is officially tested by boost for this version (stated in their website) with the same results. It's also worth mentioning that when building the debug version of the libraries and executable, everything works fine.

edit: here is the linking command:

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 \

Any idea what could be wrong?

Just happened to see this randomly - I ran into a similar problem today. The issue is that BOOST_WAVE_SUPPORT_THREADING=0 indirectly causes the fast pool allocator to use an internal null_mutex instead of std::mutex . The fix is to ensure you build the executable with the same BOOST_WAVE_SUPPORT_THREADING=0 and it should expect the null_mutex version instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM