Flags Makefiile

I'm trying to find out what a Makefile should look like when it comes to flags, especially related ones. Here is my Makefile:

OBJS = no SOURCE = n.cpp # HEADER = there are no header files, so I commented that OUT = test CXX = ../mpich-install/bin/mpic++ FLAGS = -I../intel/mkl/include ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a -Wl,--start-group ../intel/mkl/lib/intel64/libmkl_intel_ilp64.a ../intel/mkl/lib/intel64/libmkl_core.a ../intel/mkl/lib/intel64/libmkl_sequential.a -Wl,--end-group ../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_ilp64.a -lpthread -lm -ldl all: $(OBJS) $(CXX) $(OBJS) -o $(OUT) $(FLAGS) # create/compile the individual files >>separately<< no: n.cpp $(CXX) -c n.cpp $(FLAGS) .PHONY : all # clean house clean: rm -f $(OBJS) 

and then I get:

 ../mpich-install/bin/mpic++ -c n.cpp -I../intel/mkl/include ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a -Wl,--start-group ../intel/mkl/lib/intel64/libmkl_intel_ilp64.a ../intel/mkl/lib/intel64/libmkl_core.a ../intel/mkl/lib/intel64/libmkl_sequential.a -Wl,--end-group ../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_ilp64.a -lpthread -lm -ldl g++: warning: ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a: linker input file unused because linking not done g++: warning: ../intel/mkl/lib/intel64/libmkl_intel_ilp64.a: linker input file unused because linking not done g++: warning: ../intel/mkl/lib/intel64/libmkl_core.a: linker input file unused because linking not done g++: warning: ../intel/mkl/lib/intel64/libmkl_sequential.a: linker input file unused because linking not done g++: warning: ../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_ilp64.a: linker input file unused because linking not done ../mpich-install/bin/mpic++ no -o test -I../intel/mkl/include ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a -Wl,--start-group ../intel/mkl/lib/intel64/libmkl_intel_ilp64.a ../intel/mkl/lib/intel64/libmkl_core.a ../intel/mkl/lib/intel64/libmkl_sequential.a -Wl,--end-group ../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_ilp64.a -lpthread -lm -ldl 

This means that I should use some flags only in the last part of the process. What is the right way to handle this? Maybe create FLAGS1 and FLAGS2 ? It should work, but I want to know which way is right.

+5
source share
1 answer

"... but I want to know which way is right."

The right way is to keep up with the names of the standard make variables, in particular CXXFLAGS and LDFLAGS .

You do not want to specify libraries for linker flags, as you are trying to do here (by specifying topics in fact):

 FLAGS = ... ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a 

Instead of using FLAGS and providing a direct object for binding, you should rather use the standard make2 variable for LDFLAGS to set the path and let the linker find the appropriate static or shared libraries:

  LDFLAGS += -L../intel/mkl/lib/intel64 -lmkl_scalapack_ilp64 # ^^^^^^^ Note the standard build system uses $(LDFLAGS) at the linker stage rule # -L specifies the paths for finding libraries # -l<MyLib> actually searches for certain libraries in the given paths, # expanding to search for files like libMyLib.a or libMyLib.so. all: $(OBJS) $(CXX) $(OBJS) -o $(OUT) $(CXXFLAGS) $(LDFLAGS) # ^^^^^^^^^^ Use them separately at # linking stage make -f Makefile clean # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This whole line looks very (!!!) suspicious, # and would just make it harder to debug your # build system. It an indicator, you did # dependencies management wrong. # Consider to use the compiler --MF options # family, to create a dependency file for the # headers, and include it in your makefile. 

Differences from compilation phase flags ( CXXFLAGS ) and scene flag bindings ( LDFLAGS ).


Besides

To avoid this

 make -f Makefile clean 

in your final target rule (maybe this was added to avoid being absent, to catch up with the header dependencies), add the -MF parameter to CXXFLAGS and include the results.

Here is more detailed information about the various methods:

Autosendency Generation

+4
source

All Articles