When I type make I get:

Linking CXX executable ../../bin/MyProgram
../../lib/libMP.a(MPL.cpp.o): In function `_GLOBAL__sub_I_mult_fmm2':
MPL.cpp:(.text.startup+0x15): undefined reference to `boost::system::generic_category()'
MPL.cpp:(.text.startup+0x1a): undefined reference to `boost::system::generic_category()'
MPL.cpp:(.text.startup+0x1f): undefined reference to `boost::system::system_category()'
../../lib/libThing.a(vases.cpp.o): In function `_GLOBAL__sub_I__ZN9Thing6VasesC2ERKN3Two9DimensionENS1_8DataTypeE':
Vases.cpp:(.text.startup+0x15): undefined reference to `boost::system::generic_category()'
Vases.cpp:(.text.startup+0x1a): undefined reference to `boost::system::generic_category()'
Vases.cpp:(.text.startup+0x1f): undefined reference to `boost::system::system_category()'

...

../../lib/libThing.a(HDF5_IO.cpp.o): In function     `Thing::HDF5_IO::createVolumeFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Two::GenericBoundingBox<double> const&, Two::Dimension const&, std::vector<Two::DataType, std::allocator<Two::DataType> > const&, unsigned int, unsigned int, double, double) const':
HDF5_IO.cpp:(.text+0x79c5): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
../../lib/libThing.a(HDF5_IO.cpp.o): In function `Thing::HDF5_IO::writeVolumeFile(Thing::Volume const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int, unsigned long, unsigned long, unsigned long, bool) const':
HDF5_IO.cpp:(.text+0x97d1): undefined reference to `boost::thread::start_thread_noexcept()'
HDF5_IO.cpp:(.text+0x9b77): undefined reference to `boost::thread::join_noexcept()'
HDF5_IO.cpp:(.text+0x9fbb): undefined reference to `boost::thread::join_noexcept()'

...

and my link.txt file looks like

/usr/bin/g++    -O3 -O3 -DNDEBUG   CMakeFiles/MyProject.dir/main.cpp.o      
-o ../../bin/MyProject  -L/home/myname/Desktop/MyProject/build/lib -rdynamic -lboost_thread-mt -lboost_date_time-mt -lboost_regex 
-lboost_filesystem-mt -lboost_program_options-mt ../../lib/libfftw3.a  -lxcb -lXau -lXext -lX11 -lpetsc -lmpich -lmpl -lrt ../../lib/libflapack.a 
-lgfortran ../../lib/libfblas.a -lgfortran ../../lib/libMyProjectAPI.a -lfftw3  -lGLU -lGL -lpthread ../../lib/libfftw3.a -lxcb -lXau -lX11 -lpetsc -lmpich -lmpl -lrt 
../../lib/libflapack.a -lgfortran ../../lib/libfblas.a -lgfortran ../../lib/libfblas.a -lpthread -lboost_thread-mt -lboost_date_time-mt -lboost_regex 
-lboost_filesystem-mt -lboost_system-mt     -lboost_program_options-mt /home/myname/anaconda2/lib/libhdf5.so /home/myname/anaconda2/lib/libhdf5_hl.so 
-lrt /home/myname/anaconda2/lib/libz.so -ldl -lm /home/myname/anaconda2/lib/libhdf5_cpp.so 
/home/myname/anaconda2/lib/libhdf5_hl_cpp.so /home/myname/anaconda2/lib/libhdf5.so /home/myname/anaconda2/lib/libhdf5_hl.so -lrt /home/myname/anaconda2/lib/libz.so 
-ldl -lm /home/myname/anaconda2/lib/libhdf5_cpp.so /home/myname/anaconda2/lib/libhdf5_hl_cpp.so -Wl,-rpath,/home/myname/Desktop/MyProject/build/lib:/home/myname/anaconda2/lib 

Anyone know how to solve this? If I replace -lboost_system-mt with ../../lib/libboost_system-mt.a then I get the same error. And I see that in /home/myname/Desktop/MyProject/build/lib that libboost_system-mt.a clearly exists, so removing the -mt is not the problem.

I think the problem is because I'm trying to link the executable against libraries built with another compiler. I'm using g++ 5.2 and boost is already installed in usr/include. The program code I'm using has those libboost files in /home/myname/Desktop/MyProject/build/lib. I got this code to work properly on an original computer, but am now having these linker errors on my new computer. That original computer used g++ on I think version 4.8

I already installed libboost-system-dev on my new computer and it says I already have the latest version. Same when I try to install libboost-system-dev. However, locate libboost_system-mt.a shows that libboost_system-mt.a is not in usr/lib but only in /home/myname/Desktop/MyProject/build/lib

Dani AI

Generated

The undefined references to boost::system::generic_category and the std::__cxx11 types in your errors strongly suggest an ABI mismatch: you are linking object files built with GCC 5.2 (new libstdc++ ABI) against Boost archives that were built with an older GCC on your previous machine (old ABI). GCC 5 introduced a dual ABI controlled by the _GLIBCXX_USE_CXX11_ABI macro; mixing objects built with different values produces exactly these symptoms. (gcc.gnu.org)

What actually fixes it:

  • Best: stop using the old Boost archives under build/lib and link against Boost built for your current toolchain (eg, install your distro’s libboost*-dev that matches GCC 5+, or rebuild Boost with your current g++). Then reconfigure and rebuild from a clean tree.

  • If you cannot rebuild Boost immediately, compile all of your code with the old ABI so it matches the prebuilt Boost:

    # CMakeLists.txt
    target_compile_definitions(MyProject PRIVATE _GLIBCXX_USE_CXX11_ABI=0)

    Apply that to every target that links with those Boost libs.

Also check static link order. Archives are searched left-to-right; a library must appear after the objects/libs that need it. If there are circular deps across static .a files, wrap them as a group so the linker rescans:

# Example (g++)
-Wl,--start-group  ../../lib/libThing.a ../../lib/libMP.a \
-lboost_filesystem-mt -lboost_system-mt -lboost_thread-mt  \
-Wl,--end-group

This forces ld to repeatedly search the grouped archives until symbols are resolved. Use it sparingly, as it slows linking. (sourceware.org)

Quick sanity checks:

  • Verify the symbol is in your archive:

    nm -C /home/myname/Desktop/MyProject/build/lib/libboost_system-mt.a | grep 'generic_category()'
  • Remember ’s LD_LIBRARY_PATH tip affects runtime lookup of shared libs, not resolution of undefined symbols at link time for static archives.

Recommended Answers

All 2 Replies

You probably need to add a "-L <boost-library-path>" and "-l boost_system-mt" to your make file linkage (usually LFLAGS). FWIW, you are also looking for a statically linked boost library. Most are shared libraries, which you should use unless you REALLY need static linkage. Since the library is in your build area, my guess is that you did not run "make install" as root after you build the libraries. You CAN add /home/myname/Desktop/MyProject/build/lib to your LD_LIBRARY_PATH environment variable... May or may not work.

BTW, have you ever built/installed 3rd party libraries on Linux/Unix before?

I'm rather new to Linux and Unix so I apologize that I don't follow alot of what you're saying

In which makefile and where in that makefile do I add "-L <boost-library-path>" and "-l boost_system-mt" ? My makefiles contents are below:
for makefile in /home/myname/Desktop/MyProject/build
http://pastebin.com/TVq5fmPw for makefile in /home/myname/Desktop/MyProject/

I did notice in that second makefile that CMAKE_COMMAND is referring to gcc-4.6 and the different version of linux, which were for my original computer. I'm now using gcc-5.2 on a different version of Linux. _SOURCE_DIR and _BINARY_DIR are also set to the directory in my previous computer and not my current one. Do I need to modify these so they point to the directories in my current computer? I just tried to modify them to the correct directories in my new computer (such as changing CMAKE_COMMAND = /opt/olddirectory/cmake/cmake-2.8.9/oldlinuxversion/gcc-4.6/bin/cmake to CMAKE_COMMAND = /usr/bin/cmake), but I still get the same error when I type make in the build directory

Since the library is in your build area, my guess is that you did not run "make install" as root after you build the libraries

I don't understand what you're saying. You mean I should type make install instead of make to build and link my program? Or do you mean for boost?

You CAN add /home/myname/Desktop/MyProject/build/lib to your LD_LIBRARY_PATH environment variable... May or may not work

I just tried this but I got the same error as before

BTW, have you ever built/installed 3rd party libraries on Linux/Unix before?

other than with sudo apt-get, no I haven't

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.