9

Recently I installed Eclipse Indigo Service Release 2(for JAVA EE) and installed CDT 8 online.Then I installed Cygwin with gcc,g++,gdb,make,binutils,automake,etc at the latest version.I had also made the environment variable PATH correct.

Making a new C++ project(using Cygwin GCC toolchain) is just fine,but after typing a HelloWorld program,it shows lots of errors and warings.

When using external builder,in error it shows

"Cannot run program "make": ?????????¨?".

When using internal builder,in conclose it shows

"g++ -IC:\cygwin\lib\gcc\i686-pc-cygwin\4.5.3\include\c++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\test_cpp.o ..\src\test_cpp.cpp

Error: Cannot run program "g++": ?????????¨?

Build error occurred, build is stopped

In both Windows CMD and Cygwin Terminal,g++ and make both work well.

What's more,Eclipse can't find the including libraries,so I have to add the path C:\cygwin\lib\gcc\i686-pc-cygwin\4.5.3\include\c++ to the project properties->C/C++ Building->Settings.But after that, in error,it still shows,

'std' is ambiguous '

Invalid overload of 'endl'

Symbol 'cout' could not be resolved

In project properties->C/C++ Building->Discovery Options,I set the Discovery Profile scope as Configeration-wide and Discovery profile as GCC per file scanner info profile.

Community
  • 1
  • 1
user1377046
  • 147
  • 1
  • 1
  • 7

6 Answers6

6

You have to setup a Cygwin toolchain, first of all install Cygwin with the following packages :

binutils
gcc
gcc-core
gcc-g++
gcc-mingw-core
gcc-mingw-g++
make

Add %cygwin%\bin to your PATH environment variable, then open Eclipse and Cygwin toolchain will be shown when you open a new c/cpp project wizard.

aleroot
  • 71,077
  • 30
  • 176
  • 213
4

Did you try this Eclipse CDT and Cygwin tutorial for C++?

Patapoom
  • 794
  • 1
  • 7
  • 16
2

I had similar error and what worked for me is below: In the settings: 'Project|Properties|C/C++ General|Indexer', I unchecked 'Allow heuristic resolutions of includes' and saved the settings. After rebuilding, all my errors like ''std' is ambiguous ...' disappeared.

Chand51
  • 924
  • 6
  • 10
2

Have you checcked which Binary parser are you using?

Right click on your project, Properties, C/C++ Build, Settings, Binary Parsers tab, select PE Windows Parser if you are using Windows OS or Elf Parser for Linux OS.

Nenad Bulatović
  • 7,238
  • 14
  • 83
  • 113
2

Giving all basic steps to write hello world program with eclipse + CDT + cygwin-gcc.

You must have missed some steps from 3 to 7.

  1. Install cygwin with packages binutils,gcc-core, gcc-g++, gdb and make. I earlier did not insalled any packages. So I installed the packages after installing cygwin. You can install them by rerunning cygwin's setup exe (Point 3 in this answer) or by using apt-cyg as described in this answer:
  2. Install CDT plugin in eclipse or install CDT eclipse.
  3. Set windows path environment variable to include cygwin bin (C:\Program Files\cygwin\setup\bin) and lib (C:\Program Files\cygwin\setup\lib) directory paths. Set windows classpath environment variable to include cygwin lib directory path.
  4. Run commands gcc,g++,gdb and make in windows command prompt to check if the installed cygwin packages are reachable and are not giving command not found error. For gcc,g++ and make, it should give input or target file not found error. For gdb, it should start gdb prompt, which you can escape by typing Quit in gdb prompt.
  5. Start eclipse and do File > New > C/C++ Project
  6. Select C/C++ Managed build: enter image description here
    Click Next>.
  7. Give suitable project name. Select Cygwin GCC in toolchain:
    enter image description here
    It should create new project and include desired header files from cygwin lib directory specified in environment variables:
    enter image description here
  8. Right click on the project created in project explorer > hover on New in context menu > click Source Folder. Give name src to new source folder.
    enter image description here
  9. Right click on source folder and add new C source file HelloWorld.c: enter image description here
  10. Right click on the project and select Build Project. It should create debug files and executable binaries:
    enter image description here
  11. Right click on open c file, Run as > Local C/C++ Application. It should run the executable generated in earlier step.
Mahesha999
  • 22,693
  • 29
  • 116
  • 189
  • Step 7 not clear. The include files/folders are truncated. – Amit Ruhela Apr 16 '20 at 12:13
  • Only first screen shot in the step 7 describes the action to be performed in that step. Second screen shot shows effect of performing the action. Cropped part of 2nd image shouldnt be an issue. – Mahesha999 Apr 16 '20 at 12:37
0

The eclipse version I ran is Photon(4.8). I am running cygwin64 version 2.10.0(0.325/5/3).

I created a new directory - foo - and added the following files in it:

CMakeLists.txt:

set(CMAKE_C_FLAGS "-g -O0")
set(CMAKE_CXX_FLAGS "-g -O0 --std=c++17")
add_executable (foo main.cpp)

Note that "-g -O0" are needed for source level debugging.

main.cpp:

#include <iostream>

using namespace std;

int
main()
{
    cout << "Hello World" << endl;
    auto i = 5;
    cout << i << endl;
}

In the foo directory, I then ran:

cmake .

I then opened eclipse.

File->Import C/C++->Existing Code as Makefile Project

Hit Next

I set Existing Code Location to my foo directory (by browsing to it)

This automatically set the name of my project to foo (you can change it if you like)

In "Toolchain for Indexer Settings" set "none" for now and Finish. We will fix this later.

Now in the "Project Explorer" pane, right click "foo" and go to "Properties"

Go to "C/C++ Build"

Go to "Tool Chain Editor"

Uncheck "Display compatible toolchains only"

In "Current toolchain" pulldown, select "Cygwin GCC"

Hit "Apply and Close"

Once again, in the "Project Explorer" pane, right click "foo" and go to "Properties"

Go to "C/C++ Build"

Go to "Environment"

Make sure the "CYGWIN_HOME" env variable is set correctly. The default setting is "C:\cygwin", but this was not good for me and caused lots of problems. In my case it was C:\cygwin64

Hit "Apply and Close"

Now right click on the foo project again and click "Build Project"

Under foo in the Project Pane, click main.cpp to display it. Set a breakpoint somewhere.

Hit F11

You should take the breakpoint that you had set earlier.

Hope this helps.

sak
  • 3
  • 2