【问题标题】:gcc-4.8 (and 4.9) not recognizing -std=c++11 parameter [closed]gcc-4.8(和 4.9)无法识别 -std=c++11 参数 [关闭]
【发布时间】:2014-10-26 23:43:29
【问题描述】:

我正在尝试使用 gcc-4.9 编译我为 Web 服务器 (https://github.com/eidheim/Simple-Web-Server) 下载的代码示例,但出现无法解决的错误:

src$ make
Makefile:45: http_examples.d: No such file or directory
/usr/bin/gcc-4.9 -MM http_examples.cpp -MT "http_examples.o http_examples.d" -MF http_examples.d
In file included from /usr/include/c++/4.9/regex:35:0,
                 from server_http.hpp:6,
                 from http_examples.cpp:1:
/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and    library support for the ISO C++ 2011 standard. This support is currently experimental, and must be   enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \

^

我已经尝试了两种编译器选项,但都没有解决问题。以下是 make 文件中的相关位:

PROJECT = ToolBoxServer
# Compiler
CC = /usr/bin/gcc-4.9

# Run Options       
COMMANDLINE_OPTIONS = /dev/ttyS0

# Compiler options during compilation
COMPILE_OPTIONS = -std=c++11 -pedantic -Wall -Wno-long-long -ggdb3 -gstabs -O0 -pthreads

#Header include directories
HEADERS =  -I/usr/local/include -I./ -I/usr/local/include/boost
#Libraries for linking
LIBS = -lm -lmysqlcppconn
# Dependency options
DEPENDENCY_OPTIONS = -MM

# Compile every cpp file to an object
%.o: %.cpp
        $(CC) -c $(COMPILE_OPTIONS) -o $@ $< $(HEADERS)

我使用的是 gcc-4.8。我读到 gcc 4.9 对正则表达式有(更好的)支持并安装了它,但我得到了同样的错误。

有人遇到过吗?据我所知,gcc-4.9 是可用的最类似于 c++11 的编译器。任何人都可以提出解决此问题的方法吗?

谢谢

迈克

【问题讨论】:

  • -std=c++11 用于 C++,所以你应该使用g++,而不是gcc
  • 这不是他错误的原因。这可能最终导致链接错误,但gcc 支持-std=c++11 选项,并且由于.cpp 扩展名,他的代码将编译为C++。
  • 这不是 gcc/g++ 问题。这是一个 Makefile 问题。

标签: c++ gcc c++11 makefile gcc4.9


【解决方案1】:

您没有包含 makefile 中的所有相关位。值得注意的是,您没有从您的 makefile 中包含如下所示的规则:

%.d: %.cpp
     $(CC) -MM $< -MT "$(@:.d=.o) $@" -MF $@

您收到错误是因为此规则使用的编译选项与您在正常调用 GCC 时使用的编译选项不同。如果您将$(COMPILE_OPTIONS) 也添加到此规则中,您应该不会再收到错误消息了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    相关资源
    最近更新 更多