【问题标题】:Makefile, modify command based on the OSMakefile,根据操作系统修改命令
【发布时间】:2020-08-01 10:25:42
【问题描述】:

看完this的问题,我写了一个以

开头的Makefile
CXX=g++
CXXFLAGS= -std=c++17  -Wall -O3 -g

ifeq ( $( shell uname ), "Linux" )
CXXFLAGS += -fopenmp
endif


LIBS= -pthread
INCLUDES = -I.
TARGETS= my targets...

仅当我在 linux 上编译而不是在 Mac 上编译时,我才需要传递 -fopenmp 标志。

我的问题是这不起作用,并且标志永远不会通过。

【问题讨论】:

    标签: c++ linux makefile conditional-compilation


    【解决方案1】:

    gmake 的语法对空格非常敏感(尤其是gmake 宏)。此外,uname 的输出不包含引号。

    这应该是:

    CXX=g++
    CXXFLAGS= -std=c++17  -Wall -O3 -g
    
    ifeq ($(shell uname),Linux)
    CXXFLAGS += -fopenmp
    endif
    
    zz:
        echo $(CXXFLAGS)
    

    结果:

    $ make zz
    echo -std=c++17  -Wall -O3 -g -fopenmp
    -std=c++17 -Wall -O3 -g -fopenmp
    

    【讨论】:

    • 现在可以使用了。没想到对空格这么敏感
    猜你喜欢
    • 2019-05-08
    • 2012-02-06
    • 2014-01-23
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 2023-03-27
    • 2016-03-15
    • 2014-07-31
    相关资源
    最近更新 更多