2012-07-29 54 views
0

我在Ubuntu 12.04上運行Eclipse CDT(Eclipse v.4.2)。當我創建一個C++項目(在項目類型 - >可執行 - > Hello World C++項目中)並選擇Linux GCC工具鏈時,標準hello world應用程序編譯並運行得很好。當我試圖創建一個空的項目(從同樣的菜單,之前),選擇Linux的GCC工具鏈也,它帶來了一些構建錯誤:eclipse 4.2 cdt與Ubuntu 12.04配置

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' 

當我比較路徑設置(屬性 - > C/C++生成和C/C + +一般)爲由「Hello World C++項目」生成的.cpp文件,併爲.cpp文件添加到「空項目」他們有相同的配置和設置,所以我不知道爲什麼空項目沒有檢測到標準庫和編譯。包含文件夾中的所有文件也是相同的。這也發生在我的Windows 7(MingW編譯器)安裝和我的MacOS X安裝上。現在我可以創建我的項目作爲「Hello World C++項目」,擺脫文本並編寫我想要的代碼,但我對如何從頭開始設置好奇,特別是因爲我的理解是,在Executable文件夾下創建一個「Empty Project」(與創建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生成只是默認的Hello World代碼:

#include <iostream> 
    using namespace std; 

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

在此先感謝。

回答

0

我已經看到一些在雜誌上銷售的Ubuntu 12.04 DVD在默認情況下不會安裝gnu G ++。轉到Ubuntu軟件中心並安裝G ++(GNU C++編譯器工具鏈)。安裝完成後,右鍵單擊IDE左側的Eclipse Project Explorer中的項目名稱。在索引項目下選擇重建。這應該解決與iostream包括等問題。