Reputation: 1838
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?
Upvotes: 0
Views: 2835
Reputation: 31
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.)
Upvotes: 3
Reputation: 13003
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:
See also:
Upvotes: 1