阅读了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上编译时才需要传递-fopenmp
标志,而在Mac上则不需要。
我的问题是,这不起作用,并且标志永远不会通过。
答案 0 :(得分:2)
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