c++ - 如何在 makefile 中设置编译标志?

标签 c++ c++11 makefile

我习惯在 IDE 中编程,但最近切换到 vim 和插件。现在我尝试为一个 c++ 项目编写一个 makefile,但是不知何故,如果我运行 make 我总是会得到错误

g++    -c -o *.o createOutput.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
                 from createOutput.cpp:5:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^

这是我的生成文件:

CC = clang++

# compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system

all: program.exe clean

program.exe: *.o
    $(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML) 

getInput.o: getInput.cpp
    $(CC) -c getInput.cpp $(CFLAGS) 

createOutput.o: createOutput.cpp
    $(CC) -c createOutput.cpp $(CFLAGS) 

main.o: main.cpp
    $(CC) -c main.cpp $(CFLAGS)

.PHONY: clean
clean:
    rm *.o
    @echo clean done

我的错误在哪里?为什么使用 g++ 而不是 clang?为什么不使用 -std=c++11 参数?对于初学者的问题,很抱歉,很遗憾,我无法通过谷歌找到解决方案。

最佳答案

你想设置 CXXFLAGS,它会被 make 自动获取(并发送给你的编译器(eg g++clang++)。

关于c++ - 如何在 makefile 中设置编译标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34535871/

相关文章:

c++ - 将复制返回的值分配给引用

c++ - 将一对成员分配给变量

linux - Make 无法看到除 gcc 之外的命令(配方)

gcc - 如何在 Mac 上使用 Emscripten emcc 和 make 时包含 ncurses

c++ - boost::thread 在终止时会自动从 boost::thread_group 中删除吗?

c++ - gprof:具体函数时间

c++ - 如何重载加法运算符以执行交换计算?

c++ - 标识符 "__readgsqword"未定义 - Visual Studio 2017

c++ - Raspberry Pi 优化的 backtrace()

makefile - 如何在 GNU Make 中以编程方式定义目标?