在使用G++编译单个文件时,如果需要c++11标准的支持,直接在编译命令添加-std=c++11

但是,如果是多个文件联合编译时,使用makefile文件,怎么添加c++11标准?

两种方式:
1)在makefile文件中的每个g++命令中加上-std=c++11;如下:

hw07: test.o functions.o
    g++ -std=c++11 test.o functions.o -o hw07
test.o: test.cpp headerfile.h
    g++ -std=c++11 -c test.cpp
functions.o: functions.cpp  headerfile.h
    g++ -std=c++11 -c functions.cpp
clean:
    rm *.o hw07

2)或者使用另外一种方式:

CPP_FLAGS='-std=c++11'

hw07: test.o functions.o
    g++ ${CPP_FLAGS} test.o functions.o -o hw07
test.o: test.cpp headerfile.h
    g++ ${CPP_FLAGS} -c test.cpp
functions.o: functions.cpp  headerfile.h
    g++ ${CPP_FLAGS} -c functions.cpp
clean:
    rm *.o hw07

参考:how to add -std=c++11 to make file

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐