Eclipse CDT C++ error - c++

I have just installed Eclipse CDT on my machine for developping C++ applications.
I have created a new C++ project. I have copied a cpp file.
When I click the build button, the project compile without errors.
However, I have a problem. The problem is that Eclipse tell me that there is many errors. For example Eclipse show that "using namespace std" is an error or that "#include " is an error.
I don't know what is the problem with Eclipse because my file compile properly when i click the "build" button.
Is there some settings that I did not set properly?
Thanks!

You need to add the paths to the std libraries to your project in eclipse. It seems that somehow eclipse did not find your std library.
You need to add the path to your gcc include under:
properties->C/C++ General->Paths and Symbols->Includes->GNU C and GNU C++
The paths GCC/G++ uses can be found by the commands in this answer to "Where does gcc look for C and C++ header files?".

Requires a restart of eclipse to be active.

Install the GNU C++ Compiler g++, using the command:
sudo apt-get install g++

In my case (I am using TDM GCC installed on a non-standard location on Windows), I had to add the Path variable to the project. I did it by Project->Properties->C/C++ build->build variables. The value to the Path variables are auto read when one clicks on add and then select Path from the drop down list. Once the Path variable is added the C/C++ index needs to be rebuild.

Related

Unresolved Inclusions using C++ [duplicate]

I download eclipse for c++ (cdt-master-8.0.2.zip).
When I write:
#include <iostream>
It marks:
Unresolved inclusion: <iostream>
How can I fix it?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries.
Make sure that your file has .cpp extension and not .c, I just had this problem
I tried all previously mentioned answers, but in my case I had to manually specify the include path of the iostream file. As I use MinGW the path was:
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
You can add the path in Eclipse under:
Project > C/C++ General > Paths and Symbols > Includes > Add. I hope that helps
Install gcc.
If you're on linux, use the package manager.
If you're on Windows, use MinGW.
In my case, it was not the CDT GCC Built-in Compiler Settings. Only after I included CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.
It sounds like you haven't used this IDE before. Read Eclipse's "Before You Begin" page and follow the instructions to the T. This will make sure that Eclipse, which is only an IDE, is actually linked to a compiler.
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
I'm using Eclipse with Cygwin and this worked for me:
Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and select "CDT GCC Built-in Compiler Settings Cygwin [Shared]".
For those using a fresh install of Ubuntu, or another Linux distro,
make sure your have at least the package "build-essential" before you try to compile Eclipse CDT projects.
At Terminal, type:
sudo apt-get install build-essential
It should be enough to compile and run your apps.
Of course, you can also perform full g++ install, using:
sudo apt-get install g++
I am running eclipse with cygwin in Windows.
Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and selecting "CDT GCC Built-in Compiler settings Cygwin" in providers list solved problem for me.
Also set ${COMMAND} to g++ on Linux
Under:
Project
Properties
C/C++ General
Preprocessor Include Paths, Macros, etc.
Providers
CDT GCC Built-in Compiler Settings
Command to get compiler specs
Replace:
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
with:
g++ -std=c++11 -E -P -v -dD "${INPUTS}"
If you don't do this, the Eclipse stdout shows:
Unable to find full path for "-E"
and logs under ${HOME}/eclipse-workspace/.metadata/.log show:
!ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
!MESSAGE Error: Cannot run program "-E": Unknown reason
because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.
I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.
C version of the question: "Unresolved inclusion" error with Eclipse CDT for C standard library headers
Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.
On Windows, with Eclipse CDT Oxygen, none of the solutions described here worked for me. I described what works for me in this other question: Eclipse CDT: Unresolved inclusion of stl header.
I'd had this issue with Eclipse 2019-12 where the includes were previously being resolved, but then weren't. This was with a Meson build C/C++ project. I'm not sure exactly what happened, but closing the project and reopening it resolved the issue for me.

How to solve "Unresolved inclusion: <iostream>" in a C++ file in Eclipse CDT?

I download eclipse for c++ (cdt-master-8.0.2.zip).
When I write:
#include <iostream>
It marks:
Unresolved inclusion: <iostream>
How can I fix it?
Click Project → Properties.
Expand C/C++ General.
Click Preprocessor Include Paths, Macros, etc.
Click the Providers tab.
Check CDT GCC Built-in Compiler Settings.
Check Use global provider shared between projects.
Click Apply and Close.
I use Eclipse for cross compiling and I have to add the explicit directories for some of the standard C++ libraries. Right click your project and select Properties. You'll get the dialog shown in the image. Follow the image and use the + icon to explicitly add the paths to your C++ libraries.
Make sure that your file has .cpp extension and not .c, I just had this problem
I tried all previously mentioned answers, but in my case I had to manually specify the include path of the iostream file. As I use MinGW the path was:
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
You can add the path in Eclipse under:
Project > C/C++ General > Paths and Symbols > Includes > Add. I hope that helps
Install gcc.
If you're on linux, use the package manager.
If you're on Windows, use MinGW.
In my case, it was not the CDT GCC Built-in Compiler Settings. Only after I included CDT GCC Built-in Compiler Settings Cygwin did the parser recognized my #include <iostream>.
It sounds like you haven't used this IDE before. Read Eclipse's "Before You Begin" page and follow the instructions to the T. This will make sure that Eclipse, which is only an IDE, is actually linked to a compiler.
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_before_you_begin.htm
I'm using Eclipse with Cygwin and this worked for me:
Go to Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and select "CDT GCC Built-in Compiler Settings Cygwin [Shared]".
For those using a fresh install of Ubuntu, or another Linux distro,
make sure your have at least the package "build-essential" before you try to compile Eclipse CDT projects.
At Terminal, type:
sudo apt-get install build-essential
It should be enough to compile and run your apps.
Of course, you can also perform full g++ install, using:
sudo apt-get install g++
I am running eclipse with cygwin in Windows.
Project > Properties > C/C++ General > Preprocessor Includes... > Providers
and selecting "CDT GCC Built-in Compiler settings Cygwin" in providers list solved problem for me.
Also set ${COMMAND} to g++ on Linux
Under:
Project
Properties
C/C++ General
Preprocessor Include Paths, Macros, etc.
Providers
CDT GCC Built-in Compiler Settings
Command to get compiler specs
Replace:
${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
with:
g++ -std=c++11 -E -P -v -dD "${INPUTS}"
If you don't do this, the Eclipse stdout shows:
Unable to find full path for "-E"
and logs under ${HOME}/eclipse-workspace/.metadata/.log show:
!ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
!MESSAGE Error: Cannot run program "-E": Unknown reason
because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.
I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.
C version of the question: "Unresolved inclusion" error with Eclipse CDT for C standard library headers
Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.
On Windows, with Eclipse CDT Oxygen, none of the solutions described here worked for me. I described what works for me in this other question: Eclipse CDT: Unresolved inclusion of stl header.
I'd had this issue with Eclipse 2019-12 where the includes were previously being resolved, but then weren't. This was with a Meson build C/C++ project. I'm not sure exactly what happened, but closing the project and reopening it resolved the issue for me.

Eclipse CDT build error: make not in path

I just recently(actually today) started using Eclipse CDT for windows. Created a project, a test C file(Hello World) added to project. Build the project, I got error as below.
Error: Program make is not found in Path -
So then I read that Eclipse CDT needs Mingw/MSYS, which I did install. Now i See that there is make.exe in
C:\MinGW\msys\1.0\bin
But Since I dont have administrator privileges, I could not add this folder containing make to the Path system variable on Windows. (I am not likely to get administrator privileges)
Now how do I work around this error to build and use CDT on windows? Any Project settings for Eclipse CDT which if added the path to make could help resolve this?
Was able to get a fix around this problem.
Added the correct paths for two exes - make and gcc/g++ (installed by Mingw/Ansys) to the User environment variable Path (Was not allowed to edit System variable Path).
But adding these paths to User environment variable Path also helped to resolve this. Now Eclipse CDT built and executed the code fine.
check environment variable path has c:/cygwin/bin or c:/mingw/bin or wherever u installed it
if makefile name is mingw32-make.exe or something else , make a copy and rename that to make.exe
The problem is simply that your IDE need to know where is the place of GNU Binary Utilities so how to deal with that simple go to
Windows -> preference -> C/C++ -> new c++ project wizerd -> makefile
then chose what are u instal for example I use MinGW so now I will chose GUN elf parse and now I need the location for c++ filt :D
you will go to place where u install minGW in default it will be C:\MinGW
and search for c++ filt.exe :D and now u done :D
and you can install minGW from
http://www.mingw.org/
Also after adding C:\MinGW\bin to PATH variable. Make sure your new project is created with MinGW GCC toolchain as shown below.

Undefined reference to Eclipse C++

I've tried more and more time, but I got the same error.
When I use an external lib, for example I'm try to work on openssl and crypto++, I receive the error: "undefined reference to (function)".
I dunno why Eclipse do that neverthless the #include are all correct.
I've tried even to add the path from Properties-C/C++ General-Path & Symbols but nothing.
Can anybody help me?
You must specify the name of the shared libraries which must be linked to the executable.
Assuming you are using the GNU toolchain, you can do it by following these steps:
Right-click on the project, then select Properties
Go under C/C++ Build -> Settings
Select GCC C Linker -> Libraries
In Libraries (-l), add the name of your libraries,
If needed, put the directory where your libraries are hosted in Library search path (-L).
I have the same problem too. I was using Eclipse CDT and trying to build my source code with OpenSSL headers and I got the same "undefined reference" problem.
To those who may be also suffering from this type of errors, try these steps:
Make sure you use the right compiler(for Ubuntu 18.04)
right click your project->preference->C/C++ Build->tool chain editor->use CDT internal Builder / Linux gcc(you can try to run HelloWorld as a test)
C/C++ Build->settings->gcc linker, see right there is a "+", click and type ssl and crypto
Rebuild your project, done.
I strongly recommend you to learn gcc compiler command line. If you have compile problem, always use the terminal and command line to see if you can compile it successfully, then compare the succeeded command with the console log in Eclipse, at where you can see the actual gcc command that used to compile your code.
A good resource for gcc command: https://www.rapidtables.com/code/linux/gcc/gcc-l.html

Adding standard libraries to C++ eclipse project

A (very) newbie C++ question:
Is there a way to automatically add the standard libraries to a C++ eclipse project? I installed the CDT Main Features plugin.
You can manually add paths to STL headers in Paths and Symbols -> Includes tab in Project Properties. This would enough for Indexer to resolve STL symbols properly.
If you need a compiler, make sure you have a visual studio installed, or cygwin;
If you install cygwin, be sure to install the gcc and g++ compiler options which are deselected by default.
Point eclipse to the installed files and you should be good to go.