Makefile,根据OS修改命令
Makefile, modify command based on the OS
看完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.
上编译时
我的问题是这不起作用,而且标志从未通过。
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
看完this问题后,我写了一个以
开头的MakefileCXX=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.
我的问题是这不起作用,而且标志从未通过。
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