I am currently trying compile my program on CentOS 7, and below error has occurred.
It works well with ubuntu 18.04, but it is not works with CentOS 7.
db/obj-db.o: In function `std::vector<std::string, std::allocator<std::string> >::_M_range_check(unsigned long) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:825: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
db/obj-db.o: In function `std::vector<int, std::allocator<int> >::_M_range_check(unsigned long) const':
/opt/rh/devtoolset-7/root/usr/include/c++/7/bits/stl_vector.h:825: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../bin/x64/libUFMatcher.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
../bin/x64/libUFMatcher.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
collect2: error: ld returned 1 exit status
make: *** [Makefile:56: ../bin/x64/MatchingServer] Error 1
3
Answers
The centos 7 has a old
gcc
version, maybe4.8.5
. But now many libraries need a more high version. You can run below commands to use a highergcc
versionCheck whether the linked target(object/lib) is compiled with the same version of gcc.
I got the same compiling issue after I had a second version of
gcc/g++
on my machine (CentOS 7). The original one was installed by yum (v4.8.5) and the other was installed from source code (v4.9.2). It looks like the manual install changes$PATH
entries order in my shell, that/usr/local/bin
went before the/usr/bin
. So when my code compiles, it just looks forgcc/g++
which comes first from the$PATH
. Since my manual installation of 4.9.2 gcc is not fully completed, there are missing libraries and its binary is under the/usr/local/bin
.Quick fix: just check your $PATH to see if it’s messed up. For me, put
/usr/local/bin
after/usr/bin
works.