skip to Main Content

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


  1. The centos 7 has a old gcc version, maybe 4.8.5. But now many libraries need a more high version. You can run below commands to use a higher gcc version

    sudo yum update -y
    sudo yum install centos-release-scl
    sudo yum install devtoolset-8 # gcc 8 is part of this toolset
    scl enable devtoolset-8 bash # make the gcc version be 8.3.1
    
    Login or Signup to reply.
  2. Check whether the linked target(object/lib) is compiled with the same version of gcc.

    Login or Signup to reply.
  3. 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 for gcc/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.

    # echo $PATH                                                  
    /usr/sbin:/usr/bin:/root/bin:/usr/local/sbin:/usr/local/bin:...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search