38

I am getting this error in the TestExecute.cpp -

"Symbol 'std' could not be resolved"

CODE

#include <iostream>
using namespace std;

I just created a executable project in Eclipse (in Windows 7) as shown below. It seems like I am selecting a toolchain that is not supported. Is it so? I have installed Cygwin and it is available in preferences.

EDIT: Based on @RobertoWilko comment, removing the line "using namespace std; " removed the error. But the binary is not created. "Launch Failed. Binary not found". How to correct this?

enter image description here

enter image description here

enter image description here

enter image description here

LCJ
  • 22,196
  • 67
  • 260
  • 418
  • 2
    No, `using namespace std;` does *not* mean that `std::` suddenly always means `std::std::` – fredoverflow Aug 05 '12 at 07:19
  • @RobertoWilko Removing the line removed the error. But the binary is not created. Do you have any idea? "Launch Failed. Binary not found" – LCJ Aug 05 '12 at 07:45
  • 1
    @Lijo- I read something [on this forum](http://www.eclipse.org/forums/index.php/t/275956/) about a similar issue, but with CrossGCC, you might want to look. I didn't mean to confuse the situation. After removing the line you have to add std::, sorry if you didn't know that. – ChiefTwoPencils Aug 05 '12 at 08:11
  • 1
    Check "paths and symbols" in "C++ General" tab. If you choose toolchain you should be see correct include paths to standard headers. Of course, it would be done only if have correctly configure environment. – Torsten Aug 05 '12 at 08:25
  • 1
    Check this solution , i had the same problem : http://stackoverflow.com/a/24981627/1161594 – USer22999299 Jul 28 '14 at 16:34

11 Answers11

28

Try out this step: https://www.eclipse.org/forums/index.php/t/636348/

Go to

Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers

  • Activate CDT GCC Built-in Compiler Settings
  • Deactivate Use global provider shared between projects
  • Add the command line argument -std=c++11.

example

Ben
  • 146
  • 1
  • 9
Hawston
  • 313
  • 3
  • 5
17

I do not know whether you have solved this problem but I want to post my solution for those might ran into the same problem.

  1. First, make sure that you have the "Includes" folder in your Project Explorer. If you do not have it, go to second step. If you have it, go to third step.

  2. Second, Window -> Preferences-> C/C++- > Build >Environment: Create two environment variables:

    a) Name: C_INCLUDE_PATH Value: /usr/include

    b) Name: CPLUS_INCLUDE_PATH Value: /usr/include/c++

Go to Cygwin/usr/include/, if you cannot find folder "c++", copy it from \cygwin\lib\gcc\i686-pc-cygwin\X.X.X\include and Then restart your Eclipse.

  1. Third, Right Click your project in Project Explorer -> Properties -> C/C++ General -> Paths and Symbols -> Includes -> Languages:GNU C++ If you can find some C++ folders in the "Include directories" then click Apply and OK. Change a bit your codes, and save it.

You will find there will be not symbol could not be resolved problems.

I documented my solution, hoping someone might get benefits.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
Frank
  • 333
  • 3
  • 6
7

You can rewrite the code likes this:

#include<iostream>
#include<stdio.h>

using namespace std;
liuzixing
  • 128
  • 5
  • 2
    "In order to solve the problem,they added a .h to the header file" misleading. It's the "old" headers that have the .h extension. The "new" (if 15 years old means new to you) stdio.h for example is called cstdio. Anyways, I don't see how this answers the question. – Cubic Aug 05 '12 at 11:52
  • 2
    Adding #include solves the problem.because std declared in this header. – App Work Aug 07 '13 at 09:10
7

For MinGW this worked for me:

  • Right click project, select Properties
  • Go to C/C++ General - Paths and Symbols - Includes - GNU C++ - Include directories
  • Select Add...
  • Select Variables...
  • Select MINGW_HOME and click OK
  • Click Apply and OK

You should now see several MinGW paths in Includes in your project explorer.
The errors may not disappear instantly, you may need to refresh/build your project.


If you are using Cygwin, there could be an equivalent variable present.

Myst
  • 553
  • 1
  • 8
  • 19
5

The includes folder in the project is probably missing /usr/include/c++. Goto your project in project explorer, right click -> Properties -> C\C++ Build -> Environment -> add -> value= /usr/include/c++. Restart eclipse.

Meera Patil
  • 51
  • 1
  • 2
3

What allowed me to fix the problem was going to: Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings, enabling that and disabling the CDT Cross GCC Built-in Compiler Settings

2

Install C++ SDK:

Help > Install New Software > Work with: path for your eclipse version > search for C++ and install C++ sdk development tools.

Example for a path: Mars - http://download.eclipse.org/releases/mars

Alaa M.
  • 4,961
  • 10
  • 54
  • 95
  • 1
    This worked for me when nothing else on the net did. I don't know if required, but after a restart I did click on "Project > C/C++ Index > Re-resolve Unresolved Includes". I'm running openSUSE (so no MinGW or Cygwin for me). – Alex Krycek Jul 21 '19 at 15:32
1

I was having this problem using Eclipse Neon on Kubuntu with a 16.04 kernel, I had to change my #include <stdlib.h> to #include <cstdlib> this made the std namespace "visible" to Eclipse and removed the error.

HebeleHododo
  • 3,620
  • 1
  • 29
  • 38
Col_Parity
  • 11
  • 4
1

This worked for me on Eclipse IDE for C/C++ Developers Version: 2020-03 (4.15.0) Build id: 20200313-1211. Also, my code is cross-compiled.

  1. Create a new project making sure it's created as a cross-compiled solution. You have to add the /usr/bin directory that matches your cross-compiler location.
  2. Add the C and C++ headers for the cross-compiler in the Project Properties.
  3. For C: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C. Add... -> The path to your /usr/include directory from your cross-compiler.
  4. For C++: Project > Properties > C/C++ General > Paths and Symbols > Includes > GNU C++. Add... -> The path to your /usr/include/c++/ directory from your cross-compiler.
  5. If you don't know your gcc version, type this in a console (make sure it's your cross gcc binary):

    gcc -v

  6. Modify the dialect for the cross-compilers (this was the trick).

  7. For C: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross GCC Compiler > Dialect. Set to ISO C99 (-std=C99) or whatever fits your C files standard.
  8. For C++: Project > Properties > C/C++ Build > Settings > Tool Settings > Cross G++ Compiler > Dialect. Set to ISO C++14 (-std=c++14) or whatever fits your C++ files standard.
  9. If needed, re-index all your project by right-clicking the project > Index > Rebuild.
0

The problem you are reporting seems to me caused by the following:

  1. you are trying to compile C code and the source file has .cpp extension
  2. you are trying to compile C++ code and the source file has .c extension

In such situation Eclipse cannot recognize the proper compiler to use.

0

Try restart Eclipse first, in my case I change different Compiler setting of the project then it shows this message, after restart it works.

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80