g++ flto and undefined references

I have this compile line with 4.9.2 to build an executable:

g++ -std=c++11 -Wno-multichar -O3 -DNDEBUG -flto -rdynamic -lboost_unit_test_framework CMakeFiles/systems_test.dir/one_variant_rule.cpp.o ../common_parsers/libcommon_parsers.so -o systems_test

This is the linking error:

/tmp/ccI7Hs6Q.ltrans0.ltrans.o:ccI7Hs6Q.ltrans0.o:function blitzq::systems_test::systems_test_suite::test_1_variant_rule_metafct::test_method(): error: undefined reference to 'blitzq::one_or_many_parser<boost::spirit::basic_istream_iterator<char, std::char_traits<char> >, unsigned long, boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::standard> >, 0l> >::one_or_many_parser()'
collect2: error: ld returned 1 exit status

When I use nm to see if the symbol is indeed defined in the shared lib

nm -C ../common_parsers/libcommon_parsers.so

I find 2 occurences of it, one with T and one with W.

According to nm’s man page, T means “The symbol is in the text (code) section” but W means “The symbol is a weak symbol”

I don’t know how to resolve this.

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.