C++ 如何处理Eclipse CDT+Cygwin?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10463975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to deal with Eclipse CDT+Cygwin?
提问by user1377046
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.
最近我安装了Eclipse Indigo Service Release 2(for JAVA EE)并在线安装了CDT 8。然后我安装了最新版本的带有gcc、g++、gdb、make、binutils、automake等的Cygwin。我还设置了环境变量PATH正确的。
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.
创建一个新的 C++ 项目(使用 Cygwin GCC 工具链)就好了,但是在键入一个 HelloWorld 程序后,它显示了很多错误和警告。
When using external builder,in error it shows
使用外部构建器时,错误显示
"Cannot run program "make": ?????????¨?".
“无法运行程序“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
"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
错误:无法运行程序“g++”:?????????¨?
发生构建错误,构建已停止
In both Windows CMD and Cygwin Terminal,g++ and make both work well.
在 Windows CMD 和 Cygwin Terminal 中,g++ 使两者都能正常工作。
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,
更重要的是,Eclipse找不到包含库,所以我必须在项目属性->C/C++中添加路径C:\cygwin\lib\gcc\i686-pc-cygwin\4.5.3\include\c++ Building->Settings.但在那之后,错误,它仍然显示,
'std' is ambiguous '
Invalid overload of 'endl'
Symbol 'cout' could not be resolved
'std' 不明确 '
“endl”的无效重载
符号“cout”无法解析
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.
在项目属性->C/C++ 构建->发现选项中,我将发现配置文件范围设置为配置范围,将发现配置文件设置为每个文件扫描仪信息配置文件的 GCC。
回答by aleroot
You have to setup a Cygwin toolchain, first of all install Cygwin with the following packages :
您必须设置 Cygwin 工具链,首先使用以下软件包安装 Cygwin:
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.
添加%cygwin%\bin
到您的 PATH 环境变量,然后打开 Eclipse,当您打开一个新的 c/cpp 项目向导时,将显示 Cygwin 工具链。
回答by Patapoom
Did you try this Eclipse CDT and Cygwin tutorial for C++?
回答by Chand51
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.
我遇到了类似的错误,对我有用的内容如下:在设置:中'Project|Properties|C/C++ General|Indexer'
,我取消选中'Allow heuristic resolutions of includes'
并保存了设置。重建后,我所有的错误,如“std”都是模棱两可的......消失了。
回答by Nenad Bulatovic
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.
右键单击您的项目、属性、C/C++ 构建、设置、二进制解析器选项卡,如果您使用的是 Windows 操作系统或 Elf Parser for Linux 操作系统,请选择 PE Windows Parser。
回答by Mahesha999
Giving all basic steps to write hello world program with eclipse + CDT + cygwin-gcc.
给出使用 eclipse + CDT + cygwin-gcc 编写 hello world 程序的所有基本步骤。
You must have missed some steps from 3 to 7.
你一定错过了从 3 到 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 pluginin 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.
- 与包安装Cygwin
binutils
,gcc-core
,gcc-g++
,gdb
和make
。我之前没有安装任何包裹。所以我在安装 cygwin 后安装了这些软件包。您可以通过重新运行Cygwin的exe文件设置(3点在安装它们这个答案),或者通过使用apt-cyg
如在描述这个答案: - 在 eclipse 中安装CDT 插件或安装CDT eclipse。
- 设置 windows
path
环境变量以包含 cygwin bin (C:\Program Files\cygwin\setup\bin
) 和 lib (C:\Program Files\cygwin\setup\lib
) 目录路径。设置 windowsclasspath
环境变量以包含 cygwin lib 目录路径。 - 运行命令
gcc
,g++
,gdb
和make
在Windows命令提示符,以检查是否安装了Cygwin包到达,并没有给未找到错误的命令。对于gcc
,g++
和make
,它应该给出输入或目标文件未找到错误。对gdb
,它应该开始gdb
提示,您可以通过键入逃脱Quit
的gdb
提示。 - 开始日食并做
File > New > C/C++ Project
- 选择 C/C++ 托管构建:
单击。
Next>
- 给出合适的项目名称。
Cygwin GCC
在工具链中选择: 它应该创建新项目并从环境变量中指定的 cygwin lib 目录中包含所需的头文件: - 右键单击在项目资源管理器中创建的项目 > 将鼠标悬停在上下文菜单中的新建 > 单击源文件夹。
src
为新的源文件夹命名。 - 右键单击源文件夹并添加新的 C?source 文件
HelloWorld.c
: - 右键单击项目并选择构建项目。它应该创建调试文件和可执行二进制文件:
- 右键单击打开的 c 文件,
Run as > Local C/C++ Application
. 它应该运行在前面的步骤中生成的可执行文件。
回答by sak
The eclipse version I ran is Photon(4.8). I am running cygwin64 version 2.10.0(0.325/5/3).
我运行的 eclipse 版本是 Photon(4.8)。我正在运行 cygwin64 版本 2.10.0(0.325/5/3)。
I created a new directory - foo - and added the following files in it:
我创建了一个新目录 - foo - 并在其中添加了以下文件:
CMakeLists.txt:
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.
请注意,源代码级调试需要“-g -O0”。
main.cpp:
主.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:
在 foo 目录中,我然后运行:
cmake .
制作。
I then opened eclipse.
然后我打开了eclipse。
File->Import C/C++->Existing Code as Makefile Project
File->Import C/C++->Existing Code as Makefile Project
Hit Next
点击下一步
I set Existing Code Location to my foo directory (by browsing to it)
我将现有代码位置设置为我的 foo 目录(通过浏览它)
This automatically set the name of my project to foo (you can change it if you like)
这会自动将我的项目名称设置为 foo (如果您愿意,可以更改它)
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"
现在在“项目资源管理器”窗格中,右键单击“foo”并转到“属性”
Go to "C/C++ Build"
转到“C/C++ 构建”
Go to "Tool Chain Editor"
转到“工具链编辑器”
Uncheck "Display compatible toolchains only"
取消选中“仅显示兼容的工具链”
In "Current toolchain" pulldown, select "Cygwin GCC"
在“当前工具链”下拉菜单中,选择“Cygwin GCC”
Hit "Apply and Close"
点击“应用并关闭”
Once again, in the "Project Explorer" pane, right click "foo" and go to "Properties"
再次,在“项目资源管理器”窗格中,右键单击“foo”并转到“属性”
Go to "C/C++ Build"
转到“C/C++ 构建”
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
确保“CYGWIN_HOME”环境变量设置正确。默认设置是“C:\cygwin”,但这对我来说并不好,并导致了很多问题。就我而言,它是 C:\cygwin64
Hit "Apply and Close"
点击“应用并关闭”
Now right click on the foo project again and click "Build Project"
现在再次右键单击 foo 项目并单击“构建项目”
Under foo in the Project Pane, click main.cpp to display it. Set a breakpoint somewhere.
在项目窗格中的 foo 下,单击 main.cpp 以显示它。在某处设置断点。
Hit F11
按 F11
You should take the breakpoint that you had set earlier.
您应该使用之前设置的断点。
Hope this helps.
希望这可以帮助。