简体   繁体   中英

eclipse 4.2 cdt with ubuntu 12.04 configuration

I am running Eclipse CDT (Eclipse v. 4.2) on Ubuntu 12.04. When I create a C++ project (Under Project type -> Executable -> Hello World C++ Project) and select the Linux GCC toolchain, the standard hello world application compiles and runs just fine. When I try to create an Empty Project (from the same menu as before), selecting the Linux GCC toolchain also, it brings several build errors:

   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'

When I compare the path settings (Properties -> C/C++ Build, and C/C++ General) for the .cpp file generated by "Hello World C++ Project", and for the .cpp file added to the "Empty Project" they have the same configurations and settings, so I am not sure why the empty project isn't detecting the standard library and compiling. All the files in the includes folder are also the same. This also happens on my Windows 7 (MingW compiler) install, and on my MacOS X install. For now I can just create my projects as a "Hello World C++ project", get rid of the text and code what I want, but I am really curious as to how to set it up from scratch, especially since it is my understanding that creating an "Empty Project" under the Executable folder (as opposed to creating a Makefile project) should include a makefile and all the necessary paths (as long as the proper toolchain is selected?).

The actual build error from the CDT console is:

    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)

The code I'm trying to run is just the default hello world code generated by eclipse:

   #include <iostream>
   using namespace std;

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

Thanks in advance.

I've seen that some of the Ubuntu 12.04 DVD's sold in Magazines do not install gnu G++ by default. Go to the Ubuntu Software Center and install G++ (GNU C++ compiler tool chain). After installation right click on your project's name in the Eclipse Project Explorer on the left side of the IDE. Select Rebuild under the Index item. This should resolve the issue with the iostream include, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM