c – 带有许多旗帜的Makefiile

前端之家收集整理的这篇文章主要介绍了c – 带有许多旗帜的Makefiile前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图了解Makefile应该是什么样子,当涉及到标志,尤其是链接标志时.这是我的Makefile:

OBJS    = n.o
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<<
n.o:    n.cpp
        $(CXX)  -c      n.cpp   $(FLAGS)

.PHONY : all
# clean house
clean:
        rm -f $(OBJS)

然后我得到:

../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++     n.o -o test     -I../intel/mkl/include  ../intel/mkl/lib/intel64/libmkl_scalapack_ilp64.a       -Wl,--end-group ../intel/mkl/lib/intel64/libmkl_blacs_intelmpi_ilp64.a  -lpthread       -lm     -ldl

这意味着我应该只在进程的最后部分使用一些标志.处理这种情况的正确方法是什么?也许创建FLAGS1和FLAGS2?它应该工作,但我想知道哪种方法正确.

最佳答案

“… but I want to know which the correct way.”

正确的方法是跟上make标准变量名,特别是CXXFLAGS和LDFLAGS.

您不想像尝试在此处那样指定链接器标志的库(实际指定主题):

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

您应该使用标准LDFLAGS makefile变量来设置路径,而不是使用FLAGS并提供直接主题进行链接,并让链接器找到适当的静态或共享库:

  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
# -lIoUs,#                                             and would just make it harder to debug your
#                                             build system. It's an indicator,you did
#                                             dependencies management wrong.
#                                             Consider to use the compiler's --MF options 
#                                             family,to create a dependency file for the 
#                                             headers,and include it in your makefile.

区别于编译阶段标志(CXXFLAGS)和链接阶段标志(LDFLAGS).

在旁边:

为了避免这种情况

make    -f      Makefile        clean

最终目标规则中的操作(可能已添加以避免错过以赶上标头依赖关系),向CXXFLAGS添加-MF选项,并包括结果.

以下是有关各种技术的更详细信息:

Auto-Dependency Generation

猜你在找的Linux相关文章