Project

General

Profile

Undefined Reference problem when linking on a CentOS 7 Linux

Added by Claudio White over 6 years ago

CentOS 7 is using GCC 4.85 and CMAKE 2.8 as default, but WT 4.0.4 (building from sources) needs at least GCC 4.9 or higher and CMAKE 3.1 or higher.

For that reason i did install devtoolset7 which uses GCC 7, and also did build CMAKE 3.9.6 from the sources and BOOST 1.6.4 too.

which cmake => /usr/local/bin/cmake

cmake ---version => cmake version 3.9.6

gcc ---version => 7.3.1 20180303 (Red Hat 7.3.1-5)

which gcc => /opt/rh/devtoolset-7/root/usr/bin/gcc

I did just compile this code using EclipseCDT Photon:

#include

#include "main.h"

#ifndef MSWINDOWS

#include

#endif

#ifndef WT_WIN32

extern char **environ;

#endif // WT_WIN32

using namespace std;

int main(int argc, char **argv) {

cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

return 0;

}

Get the following errors:

Build of configuration Release for project HelloWorld

make all

Building file: ../src/HelloWorld.cpp

Invoking: Cross G Compiler

g -std=c++1y -I/usr/include -I/usr/local/include -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloWorld.d" -MT"src/HelloWorld.o" -o "src/HelloWorld.o" "../src/HelloWorld.cpp"

Finished building: ../src/HelloWorld.cpp

Building target: HelloWorld

Invoking: Cross G Linker

g -L/usr/local/lib -L/usr/local/lib64 -o "HelloWorld" ./src/HelloWorld.o -lstdc -lwtd -lwthttpd -lwtdbosqlite3d -lboost_system -lboost_program_options -lboost_date_time -lboost_filesystem -lboost_iostreams -lboost_locale -lboost_regex -lboost_serialization -lboost_signals -lboost_thread -lboost_timer

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::validate(boost::any&, std::vector<std::_cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, std::_cxx11::basic_string<char, std::char_traits, std::allocator >*, int)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::arg[abi:cxx11]'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::detail::cmdline::cmdline(std::vector<std::_cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::_cxx11::basic_string<char, std::char_traits, std::allocator > > > const&)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, unsigned int, unsigned int)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::error_with_option_name::error_with_option_name(std::_cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::_cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::validate(boost::any&, std::vector<std::_cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::_cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, bool*, int)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::error_with_option_name::substitute_placeholders(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::to_internal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::abstract_variables_map::operator[](std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) const'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::value_semantic_codecvt_helper::parse(boost::any&, std::vector<std::_cxx11::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::_cxx11::basic_string<char, std::char_traits, std::allocator > > > const&, bool) const'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::invalid_option_value::invalid_option_value(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

/usr/local/lib/libwthttpd.so: undefined reference to `boost::program_options::validation_error::get_template[abi:cxx11](boost::program_options::validation_error::kind_t)'

collect2: Fehler: ld gab 1 als Ende-Status zurück

make: * [HelloWorld] Fehler 1

Build Failed. 1 errors, 0 warnings.

I have no idea what could be wrong here, any suggests?

Thanks in advance!


Replies (5)

RE: Undefined Reference problem when linking on a CentOS 7 Linux - Added by Claudio White over 6 years ago

One more comment...when i take the last undefined refernce in the log above and look into the lib with:

nm -D /usr/local/lib/libboost_program_options.so | c++filt | grep get_template

I see the function:

000000000005d290 T boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)

So wondering...why linker says undefined reference?

RE: Undefined Reference problem when linking on a CentOS 7 Linux - Added by Roel Standaert over 6 years ago

I think you've got an ABI mismatch issue, see here: https://gcc.gnu.org/onlinedocs/libstdc/manual/using_dual_abi.html

If you built boost from source as well, then I'd expect it to also use the new ABI, but maybe they're already detecting that you're on an older system and defaulting to the older ABI?

You can add -D_GLIBCXX_USE_CXX11_ABI=0 to your compiler options to make sure you're using the old ABI.

RE: Undefined Reference problem when linking on a CentOS 7 Linux - Added by Claudio White over 6 years ago

Thank you Roel, i will give it a try and report after:-)

RE: Undefined Reference problem when linking on a CentOS 7 Linux - Added by lm at over 6 years ago

I trust Roel's advice much more than mine, but for what it's worth, make sure when you build boost from source that it's building program_options, too? I don't know if that's somehow "optional" when building boost.

RE: Undefined Reference problem when linking on a CentOS 7 Linux - Added by Claudio White over 6 years ago

I did solved using devtoolset7 instead newer gcc from source.

    (1-5/5)