Hello, there is such a makefile:

СC= g++ CFLAGS= -c -pipe -g -Wall -W -I. LIBS= -lboost_system \ -lpthread TARGET= targ OBJECTS= main.o \ file1.o all : $(TARGET) $(TARGET): $(OBJECTS) $(CC) -o $(TARGET) $(OBJECTS) $(LIBS) main.o : main.cpp $(CC) $(CFLAGS) main.cpp file1.o : connects.cpp $(CC) $(CFLAGS) connects.cpp 

The main.o error crashes: an undefined reference to the symbol “_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEaSEPKc @@ GLIBCXX_3.4.21” /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.4/libstcdcdcdcdcdc5xc/xc/x86_64-pc-linux-gnu/5.4.4/libstcd4c4x5/4.4c command line collect2: Error: ld execution completed with return code 1 Makefile: 15: recipe execution error for targ target

however, if you manually make everything g ++ -o targ main.o file1.o -lboost_system -lpthread, then everything skips ... what could be the problem?

  • See CFLAGS. When manually invoking, they are not used. - αλεχολυτ
  • not, in the final goal CFLAGS are also not used - xperious

1 answer 1

In fact, the problem is that you will use gcc (cc) as a compiler, not g ++ (I did it like this), make for some reason ignored CC = g++ (to be sure that you also attach the full output of make) . Or add to LIBS -lstdc++ , or, which is correct, for C ++, use CXX instead of CC and CXXFLAGS instead of CFLAGS, in fact, they came up with in order to work with C ++ code.

PS And how did you even get to linking, I had file1.o without editing the target, because the file connects.o was created in it, and not file1.o .