Dr.*_*e99 3 c++ gcc makefile c++11
我最近开始了一个 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
Run Code Online (Sandbox Code Playgroud)
当我编译我的代码时,我收到下一个错误 -
无法使用初始化列表初始化非聚合类型“向量”
我正在检查这个问题,发现我需要在我的 makefile 中添加 -std=c++11 支持来解决这个问题。我将此命令添加到代码中:
g++ -std=c++11 main.o google_api.o -o 输出
但这并不是做任何改变。如果有人可以帮助我解决这个问题,我会很高兴。谢谢
改变这个:
main.o: main.cpp
g++ -c main.cpp
Run Code Online (Sandbox Code Playgroud)
到:
main.o: main.cpp
g++ -std=c++11 -c main.cpp
Run Code Online (Sandbox Code Playgroud)
你也可以使用这样的东西作为你的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)
Run Code Online (Sandbox Code Playgroud)
stackoverflow上也有类似的问题:Makefile c++11 support