【发布时间】:2016-03-22 07:02:36
【问题描述】:
我用给定的标志-std=c++11 编译我的代码,我得到了各种错误,表明我应该使用相同的标志。此外,auto 未被识别为一种类型。
生成文件:
GCCPATH = /path/gcc/5.3.0
CC = $(GCCPATH)/bin/g++
DARGS = -ggdb #debug arguments
CARGS = -std=c++11 #C arguments
WARGS = -Wall -Wextra #warning arguments
AARGS = $(DARGS) $(CARGS) $(WARGS) #all arguments
GCCLIBPATH = $(GCCPATH)/lib64
LIBS = -l curl
LIBD = -L $(GCCLIBPATH) -Wl,-rpath=$(GCCLIBPATH)
.PHONY: webspider
webspider: ../title/htmlstreamparser.o filesystem.o
$(CC) $(AARGS) -o $@ $@.cpp $+ $(LIBS) $(LIBD)
filesystem:
$(CC) $(AARGS) -c $@.cpp
我得到的警告和错误:
warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
error: ‘weblink’ does not name a type
for(auto weblink: weblinks)
现在我的问题是:我应该怎么做才能让 g++ 识别这个明确给出的标志?
我也试过用-std=c++0x替换它,但无济于事。
编辑:make的完整输出:
g++ -c -o filesystem.o filesystem.cpp
In file included from filesystem.cpp:1:0:
filesystem.hpp:23:36: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
std::string dir = getCurrentPath();
^
filesystem.cpp: In member function ‘std::__cxx11::string Filesystem::createMD5(std::__cxx11::string)’:
filesystem.cpp:49:19: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
for(long long c: result)
^
filesystem.cpp: In member function ‘void Filesystem::createLinkIndex(std::__cxx11::string, strVec)’:
filesystem.cpp:57:11: error: ‘weblink’ does not name a type
for(auto weblink: weblinks) {
^
filesystem.cpp:61:1: error: expected ‘;’ before ‘}’ token
}
^
filesystem.cpp:61:1: error: expected primary-expression before ‘}’ token
filesystem.cpp:61:1: error: expected ‘;’ before ‘}’ token
filesystem.cpp:61:1: error: expected primary-expression before ‘}’ token
filesystem.cpp:61:1: error: expected ‘)’ before ‘}’ token
filesystem.cpp:61:1: error: expected primary-expression before ‘}’ token
make: *** [filesystem.o] Error 1
【问题讨论】:
-
你不应该有
CXXFLAGS=-std=c++11吗? -
你能
make VERBOSE=1验证传递给 gcc 的选项是否正确吗? -
@NathanOliver Makefile 中变量的名称是否重要?
-
如果您的构建依赖于 implicit 命令,那么是的,名称 do 很重要。尝试设置
CXXFLAGS。 -
这里有一些非常可疑的东西——要么不是正确的 makefile,要么你有多个(在不同的目录或不同的名称)。