c++ - 支持 c++11 的 Makefile

标签 c++ c++11 gcc makefile

我最近开始了一个 C++ 小项目。我创建了一个简单的 Makefile:

output: main.o google_api.o
    g++ main.o google_api.o -o output
    rm *.o
    clear
    ./output

main.o: main.cpp
    g++ -c main.cpp

test.o: google_api.cpp google_api.h
    g++ -c google_api.cpp

当我编译我的代码时,我得到下一个错误 -

non-aggregate type 'vector' cannot be initialized with an initializer list

我正在检查这个问题,发现我需要在我的 makefile 中添加 -std=c++11 支持来解决这个问题。我将此命令添加到代码中:

g++ -std=c++11 main.o google_api.o -o output

但这不是做任何改变。如果有人可以帮助我解决这个问题,我会很高兴。谢谢

最佳答案

改变这个:

main.o: main.cpp
    g++ -c main.cpp

到:

main.o: main.cpp
    g++ -std=c++11 -c main.cpp

你也可以用这样的东西作为你的Makefile的基础。 :

CXX=g++
CXXFLAGS=-g -Wall -MMD -std=c++11
LDLIBS=-lm # list libs here
output: main.o google_api.o
clean:
    $(RM) *.o *.d output
-include $(wildcard *.d)

stackoverflow上也有类似问题:Makefile c++11 support

关于c++ - 支持 c++11 的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43423680/

相关文章:

c++ - OpenCL 仅读取/写入缓冲内存的 1/4,有时会崩溃

c++ - 指定针对具有相同名称的不同函数的类内 using 声明

c++:使用指针访问缓冲区与使用增量变量

linux - 枚举类型声明的 C++11 编译错误如预期的那样在数字常量之前

c++ - [[gnu::pure]] 函数属性和线程的优化问题

c - gcc 原子内置和可用性版本

c++ - 在硬件接口(interface)之间切换的最佳设计模式

c++ - 在 [] 运算符的情况下,为 unordered_map 中的元素设置默认构造函数

c++ - 在 Variadic 模板类中使用 std::bind

c++ - Clang 跳过初始化列表构造的处理