0

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. Anyone know how to solve this?

usr1234567
  • 17,173
  • 10
  • 96
  • 112
user5739619
  • 1,430
  • 3
  • 17
  • 32
  • What platform? Compiler? Compiler version? Where did you got these boost binaries? Try to link in verbose mode: add `-Xlinker -v`. My guess is that linker finds but ignores libraries built against an incompatible architecture and/or compiler and/or compiler version. You might want to install boost provided by your distribution's repositories – Ivan Aksamentov - Drop Jan 04 '16 at 04:46
  • 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 – user5739619 Jan 04 '16 at 04:53
  • What were the compiler and compiler version on the old machine? (specifically, the compiler that was used to build ...MyProject/build/lib libraries) – Ivan Aksamentov - Drop Jan 04 '16 at 05:42
  • The previous computer used g++. I think version 4.8. It was a different version of Linux than the one on my current computer. I had to delete the lib directory in `/home/myname/Desktop/MyProject/build/lib` because it contained boost files that are outdated and caused a huge list of errors, possibly because of a conflict since I newly installed boost files in `usr/lib `and `usr/include` on this new computer. I got this program to work on a 2nd computer by simply deleting that lib directory (that had g++ and I think also version 4.8), but it won't work on this new computer for whatever reason – user5739619 Jan 04 '16 at 06:18

2 Answers2

3

The solution was to tell CMake to link the executable against Boost by adding:

FIND_PACKAGE(Boost COMPONENTS system thread filesystem REQUIRED)
TARGET_LINK_LIBRARIES(MyProject ${Boost_LIBRARIES})

to the CMakeLists.txt where the executable was defined with the ADD_EXECUTABLE directive.

(Full debugging session on Reddit.)

fragmede
  • 31
  • 1
1

From comments it seems that you are trying to link your executable against libraries built with another compiler (or compiler version), probably on another OS (or OS version), and most likely with different C++ Standard libraries (or Standard library versions).

C++ libraries, unlike C libraries, are not binary compatible across compilers, compiler versions, operating systems, standard libraries. There is no standard ABI for C++ and mixing binaries is not supported.

You will need to find all your C++ dependencies built with your new toolchain:

  • install boost and other popular C++ libraries from your Linux distro's repositories
  • anything you couldn't find you should build yourself from sources (if they are available)

See also:

Community
  • 1
  • 1
Ivan Aksamentov - Drop
  • 12,316
  • 3
  • 30
  • 61
  • Ok, I see what you're saying. However, I already installed `libboost-system-dev` 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` – user5739619 Jan 04 '16 at 06:29