g++ -o 1 1.cpp -lpng16 # correct g++ 1.cpp -lpng16 -o 1 # correct g++ -lpng16 1.cpp -o 1 # wrong g++ -o 1 -lpng16 1.cpp # wrong
GNU make's manual. 10.3 Variables Used by Implicit Rules
- CC - Program for compiling C programs; default ‘cc’.
- CFLAGS - Extra flags to give to the C compiler.
- CXX - Program for compiling C++ programs; default ‘g++’.
- CXXFLAGS - Extra flags to give to the C++ compiler.
- CPP - Program for running the C preprocessor.
- CPPFLAGS - Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers).
- LDFLAGS - Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’. [实测好像是cc,不是ld]
- LDLIBS - Library flags or names given to compilers when they are supposed to invoke the linker.
- 没有LD. 所有还是得会会$@, $<, $^之流。
myprog: myprog.o file1.o file2.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
- $< The name of the first prerequisite.
- $^ The names of all the prerequisites.
- $+ is like ‘$^’, but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order.