IAmYourFaja
IAmYourFaja

Reputation: 56874

Getting C++ to compile inside Eclipse

Trying to get Eclipse CDT plugin to compile a simple C++ app. I create a new C++ project, and add 1 file (test.cpp) and code it up like a "Hello, world!" example:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, world!";
    return 0;
}

I get highlighted syntax errors on using namespace std and cout, stating (respectively):

Symbol 'std' could not be resolved Symbol 'cout' could not be resolved

I'm sure I didn't install CDT with everything it needed to compile/build a full C++ app. Where could I start looking to figure out what I'm missing?

Upvotes: 6

Views: 19188

Answers (2)

Philip Dodson
Philip Dodson

Reputation: 343

I don't know what OS you have, but if you are on a Mac, the following worked for me:

  1. Verify Xcode is installed.

  2. Open your Terminal window and type:

    xcode-select --install

Now the "'std' could not be resolved" error should disappear.

Now, to run your Hello World application:

  1. Click the Run icon. You are then prompted to select your Run Configuration. The Run Configuration window can also be reached by clicking the drop down arrow from the Run Icon or using the Run menu.

  2. Your configuration should be for a C++ Application. On the "Main" tab, click the "Search Project" button.

  3. In the Binaries box, there should be a binary with the name of your project pre-selected. Click OK.

  4. Click the Run button at the bottom of the "Run Configurations" window.

Hopefully your project then runs, and you see "Hello, world!" in the Console window at the bottom of Eclipse.

I would also like to add, I still have issues sometimes with std not being found. When I restart my computer, this goes away. Wish I knew why.

EDIT: This problem came back and now I can't make it go away!! Anyone know how to fix? I am sure it is something with project/compiler settings.

Upvotes: 0

ondrisko
ondrisko

Reputation: 320

Do you have a compiler? Quoting eclipse documentation: 'Eclipse IDE for C/C++ Developers does not contain a compiler or debugger; if your system does not have one, you need to download and install one. Please see the Before you begin section of the C/C++ Development User Guide.'

There you can choose and find out how to install a compiler.

Specifically for your unresolved symbols problem, you need to have correct paths set in Project->Properties->C/C++ General->Paths and Symbols/Includes tab, which depends on the compiler you choose to install.

Upvotes: 3

Related Questions