我編譯我的代碼時給出了標誌-std=c++11
,我得到各種錯誤描述我應該使用相同的標誌。另外,auto
不被識別爲一種類型。G ++似乎並不認可-std = C++ 11
的Makefile:
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 [email protected] [email protected] $+ $(LIBS) $(LIBD)
filesystem:
$(CC) $(AARGS) -c [email protected]
的警告和錯誤,我得到:
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'嗎? – NathanOliver
您是否看到該標誌是否傳遞給gcc並且只是無法識別,或者它實際上是否與makefile有關? – Anedar
@NathanOliver這就是我想說的...... – callyalater