C++ Ubuntu 12.04 C++;11代码不工作

C++ Ubuntu 12.04 C++;11代码不工作,c++,gcc,c++11,g++,eclipse-cdt,C++,Gcc,C++11,G++,Eclipse Cdt,在过去的几天里,这件事让我心烦意乱。我也不确定是在ask ubuntu中发布还是在这里发布。我选择这里是为了获得更广泛的程序员观众 我对Ubuntu和GCC是全新的,但是我在Windows上已经编程C++大约5年了。这个简单的C++11代码示例在使用VS2010的Windows机器上运行良好 #include <iostream> #include <functional> std::function<void()> func; int main() {

在过去的几天里,这件事让我心烦意乱。我也不确定是在ask 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;
}
gcc不支持这一点吗

GCC很好地支持它,您将Eclipse的一个错误与GCC的一个编译器错误混为一谈,该错误表示其语法突出显示和自动完成无法识别
std::function
。他们不是一回事

我已经在eclipse中的路径和符号中添加了
\uuuuugxx\ucx0x\uuuxx


这说明了如何让Eclipse CDT识别C++11名称:

您是否使用了--std=C++11命令行选项?是的,我已经尝试过了,并且--std=C++0x,很抱歉,我将在问题中包括这个选项。不要手动定义
\uuuugxx\ucx0x\uuuxx
。你不应该这样做。@R.Martinho Fernandes-我按照指示把它添加到eclipse的路径和符号列表中。它无论如何都不起作用:(请从命令行执行:
g++-v;g++-std=c++0x-o test test.c
,并在您的问题中包含这些命令的输出。是的,我想了很多。我发布了我自己的答案,但被删除了。尽管链接非常有用,谢谢:)
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$