G ++似乎没有认识到-std = c ++ 11

Sim*_*ver 1 c++ makefile c++11

我用-std=c++11给定的标志编译我的代码,我得到各种错误描述我应该使用相同的标志.此外,auto不承认是一种类型.

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 $@ $@.cpp $+ $(LIBS) $(LIBD)

filesystem:
    $(CC) $(AARGS) -c $@.cpp
Run Code Online (Sandbox Code Playgroud)

我得到的警告和错误:

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)
Run Code Online (Sandbox Code Playgroud)

现在我的问题是:我应该怎样做才能让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
Run Code Online (Sandbox Code Playgroud)

Gal*_*lik 5

问题是您没有指定所有依赖项,特别是如何构建所有中间目标文件.

所以发生的事情是make制定自己的规则,并在你不看的时候无形地偷偷溜进去.

控制这些隐式规则的方法是设置正确的预定义变量:

CXX := $(GCCPATH)/bin/g++      # c++ compiler
CPPFLAGS := -I/path/to/headers # preprocessor flags
CXXFLAGS := -std=c++11         # compiler flags
LDFLAGS := -L/path/to/libs     # linker flags
LDLIBS := -lcurl               # libraries to link
# etc...
Run Code Online (Sandbox Code Playgroud)

通过使用正确的预定义变量,而不是自己构建,您可以在构建时节省大量工作Makefile.