Getting C ++ to compile inside Eclipse

Trying to get the Eclipse CDT plugin to compile a simple C ++ application. I create a new project in C ++ and add 1 file ( test.cpp ) and encode it as "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 , pointing (respectively):

The character 'std' cannot be resolved. The symbol 'cout' cannot be resolved.

I am sure that I did not install CDT with everything that is needed to compile / build a complete C ++ application. Where could I start looking for what I am missing?

+6
source share
2 answers

Do you have a compiler? Quoting eclipse documentation : 'The 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 it. Please read Before You Begin in the C / C ++ Development User Guide.

Here you can choose and learn how to install the compiler.

In particular, for your problem with unresolved characters, you must have the correct paths set in the Project-> Properties-> C / C ++ General-> Paths and Symbols / Includes tab, which depends on the compiler you want to install.

+3
source

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

  • Check if Xcode is installed .

  • Open the Terminal window and enter:

    xcode-select --install

Now "std" cannot be resolved; the error should disappear.

Now, to launch the Hello World application:

  • Click the Run icon. You are then prompted to select Run Configuration . The Run Configuration window can also be found by clicking the down arrow from the Run icon or the Run menu.

  • Your configuration should be for a C ++ application. On the Home tab, click the Search Project button .

  • The Binaries block should have a binary name with the pre-selected name of your project. Click OK.

  • Click the Run button at the bottom of the Run Configurations window.

I hope your project will be launched and you will see "Hello world!". in the console window at the bottom of Eclipse.

I would also like to add, I still have problems, sometimes with std not found. When you restart your computer , it will disappear. I wish I knew why.

EDIT: This problem is back, and now I can’t get her to leave! Does anyone know how to fix it? I am sure this is something with project / compiler settings.

0
source

Source: https://habr.com/ru/post/908933/


All Articles