compiling error with make command std::__cxx11

2019-08-22 12:31发布

问题:

At first, my Makefile is written as:

.SUFFIXES: .c .cpp

CC              = g++ -fopenmp
# CFLAGS                = -c -Wall -D_I386 -D_UNIX -O2 -fPIC -Wno-deprecated -Wno-unused-result -std=c++0x -Wno-sign-compare 
CFLAGS          = -c -O2 -Wall -D_I386 -D_UNIX -fPIC -Wno-unused-result -std=c++11 -Wno-sign-compare -D_GLIBCXX_USE_CXX11_ABI=0
LFLAGS          = -shared -O2 -o
LIBS            = -llmi -lblas -lboost_regex -lpthread -lleveldb
MAINDIR = ../../../
LIBDIR  = ${MAINDIR}lib/
LD_PATH = -L${LIBDIR}
INCLUDEDIR = ${MAINDIR}include/Lheader
IN_PATH = -I${INCLUDEDIR} -I${MAINDIR}include
LM_TEST = main.o
all: lang.test clean
lang.test:$(LM_TEST)
     ${CC} -o $@ $^ ${IN_PATH} ${LD_PATH} ${LIBS}

.cpp.o:
    @echo " compiling '$<' ..."
    @$(CC) $(CFLAGS) ${IN_PATH} $<
clean:
    \rm -f *.o

But when I command make then, it takes error:

/usr/bin/ld: ../../../lib//liblmi.a(LMInterface.o): unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value

So, I update binutils with 2.26 in sudo ID like this:

$ sudo apt-get update
$ sudo apt-get install binutils
$ dpkg -l | grep binutils
ii  binutils                                  2.24-5ubuntu14.2                                    amd64        GNU assembler, linker and binary utilities
ii  binutils-2.26                             2.26.1-1ubuntu1~14.04                               amd64        GNU assembler, linker and binary utilities

Then, binutils-2.26 provides the individual programs under names such as /usr/bin/as-2.26 so, I change them like this:

PATH="/usr/lib/binutils-2.26/bin:$PATH"

But when i commanded make again, then it takes other error:

env_posix.cc:(.text+0x28bf): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

I added -D_GLIBCXX_USE_CXX11_ABI=0 in the end of the line CFLAGS, but I got the above error.

So How to solve this error?

My environment is like this (Ubuntu 14.04):

$ gcc --version
gcc (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904
$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.24