Linker input file not used C ++ g ++ make file

I cannot understand what causes this error, which I continue to make in my project:

i686-apple-darwin11-llvm-g++-4.2: -lncurses: linker input file unused because linking not done 

And my make file looks like this:

 CC = g++ LIB_FLAGS = -l ncurses FLAGS = $(LIB_FLAGS) DEPENDENCIES = window.o element.o # FINAL OUTPUTS main: main.cpp $(DEPENDENCIES) $(CC) $(FLAGS) -o main.out main.cpp $(DEPENDENCIES) # MODULES window.o: main.h classes/window.cpp $(CC) $(FLAGS) -c classes/window.cpp element.o: main.h classes/element.cpp $(CC) $(FLAGS) -c classes/element.cpp # CLEAN clean: rm -rf *.o rm main.out 

Everything compiles in order, but I'm just wondering what causes this error message and what it means.

+4
source share
3 answers

Do not specify link flags when compiling (-c) your source files. Take a look at this makefile example (very similar to a makefile)

 CPP = g++ CPPFLAGS =-Wall -g OBJECTS = main.o net.o PREFIX = /usr/local .SUFFIXES: .cpp .o .cpp.o: $(CPP) $(CPPFLAGS) -c $< .o: $(CPP) $(CPPFLAGS) $^ -o $@ main: $(OBJECTS) main.o: main.cpp net.o: net.cpp net.h .PHONY: install: main mkdir -p $(PREFIX)/bin rm -f $(PREFIX)/bin/main cp main $(PREFIX)/bin/main clean: rm -f *.o main 
+3
source

You pass the linker options to invoke the compiler along with -c , which means that the connection is not made, and so the -l options are not used. In your case, your LIB_FLAGS should not be in FLAGS , but instead is specified in the rule main: ... :

 main: main.cpp $(CC) $(FLAGS) $(LIB_FLAGS) ... 
+4
source

As already mentioned, you pass the flags associated with the linkers at the compilation stage. Usually you need different flags for compilation and linking, for example.

 CC = g++ CPPFLAGS = -Wall -g -c -o $@ LDFLAGS = -l ncurses -o $@ DEPENDENCIES = main.o window.o element.o # FINAL OUTPUTS main: $(DEPENDENCIES) $(CC) $(LDFLAGS) $(DEPENDENCIES) # MODULES main.o: main.h main.cpp $(CC) $(CPPFLAGS) main.cpp window.o: main.h classes/window.cpp $(CC) $(CPPFLAGS) classes/window.cpp element.o: main.h classes/element.cpp $(CC) $(CPPFLAGS) classes/element.cpp # CLEAN clean: -rm main $(DEPENDENCIES) 
+2
source

Source: https://habr.com/ru/post/1435442/


All Articles