G ++似乎不认识-std = c ++ 11 [英] G++ does not seem to recognize -std=c++11

查看:1449
本文介绍了G ++似乎不认识-std = c ++ 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译我的代码与标志 -std = c ++ 11 给出,我得到各种错误描述我应该使用相同的标志。此外, auto 无法识别为类型。

I compile my code with the flag -std=c++11 given, and I get all kinds of errors depicting that I should use the same flag. Also, auto is not recognised being a type.

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

我得到的警告和错误:

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 ++识别这个明确的标志? br>
我也尝试用 -std = c ++ 0x 替换它,无效。

Now my question is: What should I do to make g++ recognise this clearly given flag?
I also tried to replace it with -std=c++0x, to no avail.

编辑:

的完整输出

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


推荐答案

问题是你不指定所有的依赖,特别是如何构建所有的中间对象文件。

The problem is you do not specify all your dependencies, in particular how to build all your intermediate object files.

那么,会发生什么是 make 组成自己的规则,并且在你不看的时候隐藏它们。

So what happens is make makes up its own rules and invisibly sneaks them in while you're not looking.

控制这些隐式规则是通过设置正确的预定义变量

The way to control these implicit rules is through setting the correct predefined variables:

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...

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

By using the correct predefined variables, rather than making up your own, you can save a lot of work when building a Makefile.

这篇关于G ++似乎不认识-std = c ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆