c++ - Ubuntu 12.04 C++11 代码不工作

标签 c++ gcc c++11 g++ eclipse-cdt

<分区>

这几天一直困扰着我。我也不确定是在询问 ubuntu 还是在这里发布这个。我选择这里是为了获得更广泛的基于程序员的受众。

我是 Ubuntu 和 GCC 的新手,但是我已经在 Windows 上编写 C++ 编程大约 5 年了。这个简单的 C++11 代码示例在我装有 VS2010 的 Windows 机器上运行良好。

#include <iostream>
#include <functional>

std::function<void()> func;

int main() {
    std::cout << "!!!Hello World!!!" << std::endl; // prints !!!Hello World!!!
    return 0;
}

使用 Eclipse CDT (Ubuntu 12.04),我得到错误 Symbol 'function' could not be resolved

我已确保安装了 build-essentials

我已将 /usr/include/c++/4.6.3 添加到我在 eclipse 中的包含。

我已将 __GXX_EXPERIMENTAL_CXX0X__ 添加到 eclipse 中的路径和符号。

我已经在命令行上尝试了 -std=c++11。

我已经在命令行上尝试了 -std=c++0x。

我在这里遵循了已接受的答案:https://askubuntu.com/questions/113291/how-do-i-install-gcc-4-7并安装了 gcc 4.7

gcc 不支持吗?

我已经检查了 auto 并且它可以工作,但是 unique_ptr 之类的东西也不起作用,与上面的错误相同。

再次抱歉,我是 Linux 新手。

编辑: 根据 n.m. 的要求:

neil@ubuntu12:~/projects/Test/Test$ g++ -v;g++ -std=c++0x -o main main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
neil@ubuntu12:~/projects/test$

最佳答案

Is this not supported with gcc?

GCC 很好地支持它,您混淆了 Eclipse 的错误,说它的语法突出显示和自动完成无法识别 std::function 与 GCC 的编译器错误。它们不是一回事。

I've added __GXX_EXPERIMENTAL_CXX0X__ to Paths and Symbols in eclipse.

这说明了如何使 Eclipse CDT 识别 C++11 名称:http://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features

关于c++ - Ubuntu 12.04 C++11 代码不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11870661/

相关文章:

c++ - 对 glfwSetErrorCallback 的 undefined reference

c++ - 使用 for 循环进行线程化

objective-c - 为什么 gcc 会警告派生类中的 `self = [super initDesignatedInit];' 调用不兼容的结构赋值?

c++ - 实现构造函数是否会阻止自动移动语义?

c++11 - C++ CRTP : How to make only one (some) function of the base class as a friend to to the derived class?

c++ - : char* param= new char[200]; 可能有什么问题

c++ - 如何从 std::vector 的末尾删除几个元素?

c - 尝试通过 bash 脚本中的命令行传递预处理器指令

c - GCC 对待 int i=048;作为一个错误,为什么 GCC 不能更智能呢?

c++ - 实时获取 QProcess 的响应