eclipse 4.2 cdt with ubuntu 12.04 configuration

eclipse 4.2 cdt with ubuntu 12.04 configuration

本文关键字:configuration ubuntu with cdt eclipse      更新时间:2023-10-16

我在Ubuntu 12.04上运行Eclipse CDT(Eclipse v.4.2)。当我创建一个C++项目(在项目类型->可执行文件->Hello World C++项目下)并选择Linux GCC工具链时,标准的Hello World应用程序编译并运行得很好。当我尝试创建一个空项目(从与以前相同的菜单中),同时选择Linux GCC工具链时,它会带来几个构建错误:

   make:***[tst] Error 1
   Symbol 'cout' could not be resolved
   Symbol 'endl' could not be resolved
   Symbol 'std' could not be resolved
   undefined reference to 'main'

当我比较"Hello World C++Project"生成的.cpp文件和添加到"Empty Project"的.cpp的路径设置(Properties->C/C++Build和C/C++General)时,它们具有相同的配置和设置,所以我不确定为什么空项目没有检测到标准库并进行编译。includes文件夹中的所有文件也是相同的。这也发生在我的Windows7(MingW编译器)安装和MacOSX安装上。目前,我可以将我的项目创建为"Hello World C++项目",去掉我想要的文本和代码,但我真的很好奇如何从头开始设置它,特别是因为我的理解是,在可执行文件夹下创建"空项目"(而不是创建Makefile项目)应该包括一个Makefile和所有必要的路径(只要选择了正确的工具链?)。

CDT控制台的实际构建错误为:

    20:49:26 **** Incremental Build of configuration Debug for project tst ****
    make all 
    Building target: tst
    Invoking: GCC C++ Linker
    g++  -o "tst"  ./src/test.o   
    /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
    (.text+0x20): undefined reference to `main'
    collect2: ld returned 1 exit status
    make: *** [tst] Error 1
    20:49:26 Build Finished (took 62ms)

我尝试运行的代码只是eclipse生成的默认helloworld代码:

   #include <iostream>
   using namespace std;
   int main() {
   cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
   return 0;
   }

提前谢谢。

我看到一些在杂志上出售的Ubuntu 12.04 DVD默认不安装gnu G++。转到Ubuntu软件中心并安装G++(GNU C++编译器工具链)。安装完成后,在IDE左侧的Eclipse项目浏览器中右键单击项目名称。选择"索引"项下的"重建"。这应该可以解决iostream-include等的问题。