简体   繁体   English

Makefile支持C ++ 11

[英]Makefile to support c++11

I recently started a small project in C++. 我最近用C ++开始了一个小项目。 I created a simply Makefile: 我创建了一个简单的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

And when I compile my code I get the next error - 当我编译代码时,出现下一个错误-

non-aggregate type 'vector' cannot be initialized with an initializer list 非聚合类型'vector'不能使用初始化列表初始化

I am check for this issue and find that I need to add -std=c++11 support to my makefile to fix the problem. 我正在检查此问题,发现我需要在我的makefile中添加-std = c ++ 11支持以解决该问题。 I add this command to the code: 我将此命令添加到代码中:

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

But this is not make any change. 但这并没有任何改变。 I would love if someone can help me to fix this problem. 如果有人可以帮助我解决此问题,我将非常乐意。 Thanks 谢谢

change this: 改变这个:

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

to: 至:

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

You may as well use something like this as basis for your Makefile : 您也可以将这样的东西用作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)

There are also similar questions on stackoverflow: Makefile c++11 support 关于stackoverflow也有类似的问题: Makefile c ++ 11支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM