问题
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.
回答1:
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.
回答2:
Did you try this Eclipse CDT and Cygwin tutorial for C++?
回答3:
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.
回答4:
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.
回答5:
Giving all basic steps to write hello world program with eclipse + CDT + cygwin-gcc.
You must have missed some steps from 3 to 7.
- Install cygwin with packages
binutils
,gcc-core
,gcc-g++
,gdb
andmake
. 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 usingapt-cyg
as described in this answer: - Install CDT plugin in eclipse or install CDT eclipse.
- 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 windowsclasspath
environment variable to include cygwin lib directory path. - Run commands
gcc
,g++
,gdb
andmake
in windows command prompt to check if the installed cygwin packages are reachable and are not giving command not found error. Forgcc
,g++
andmake
, it should give input or target file not found error. Forgdb
, it should startgdb
prompt, which you can escape by typingQuit
ingdb
prompt. - Start eclipse and do
File > New > C/C++ Project
- Select C/C++ Managed build:
ClickNext>
. - Give suitable project name. Select
Cygwin GCC
in toolchain:
It should create new project and include desired header files from cygwin lib directory specified in environment variables: - 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. - Right click on source folder and add new C source file
HelloWorld.c
: - Right click on the project and select Build Project. It should create debug files and executable binaries:
- Right click on open c file,
Run as > Local C/C++ Application
. It should run the executable generated in earlier step.
回答6:
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.
来源:https://stackoverflow.com/questions/10463975/how-to-deal-with-eclipse-cdtcygwin