[英]How to deal with Eclipse CDT+Cygwin?
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(用于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
“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++": ?????????¨?
错误:无法运行程序“g ++”:??????????
Build error occurred, build is stopped
发生构建错误,构建停止
In both Windows CMD and Cygwin Terminal,g++ and make both work well. 在Windows CMD和Cygwin终端中,g ++和make都能很好地工作。
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:\\ cygwin \\ lib \\ gcc \\ i686-pc-cygwin \\ 4.5.3 \\ include \\ c ++添加到项目属性 - > C / C ++ Building-> Settings.But之后,出错,它仍然显示,
'std' is ambiguous '
'std'含糊不清'
Invalid overload of 'endl'
'endl'的重载无效
Symbol 'cout' could not be resolved
符号'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 ++ Building-> Discovery Options中,我将Discovery Profile范围设置为Configeration-wide,将Discovery配置文件设置为GCC /文件扫描程序信息配置文件。
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工具链。
您是否尝试过用于C ++的Eclipse CDT和Cygwin教程 ?
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. 我有类似的错误,对我有用的是:在设置:
'Project|Properties|C/C++ General|Indexer'
,我取消选中'Allow heuristic resolutions of includes'
并保存设置。 After rebuilding, all my errors like ''std' is ambiguous ...' disappeared. 在重建之后,我所有的错误如''std'都含糊不清......'消失了。
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 OS,请选择PE Windows Parser。
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的一些步骤。
binutils
, gcc-core
, gcc-g++
, gdb
and make
. binutils
, gcc-core
, gcc-g++
, gdb
和make
安装cygwin。 I earlier did not insalled any packages. apt-cyg
as described in this answer : apt-cyg
安装它们,如本答案中所述 : path
environment variable to include cygwin bin ( C:\\Program Files\\cygwin\\setup\\bin
) and lib ( C:\\Program Files\\cygwin\\setup\\lib
) directory paths. path
环境变量以包括cygwin bin( C:\\Program Files\\cygwin\\setup\\bin
)和lib( C:\\Program Files\\cygwin\\setup\\lib
)目录路径。 Set windows classpath
environment variable to include cygwin lib directory path. classpath
环境变量以包含cygwin lib目录路径。 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. gcc
, g++
, gdb
和make
,检查安装的cygwin软件包是否可访问,并且没有给出命令not found错误。 For gcc
, g++
and make
, it should give input or target file not found error. gcc
, g++
和make
,它应该给输入或目标文件找不到错误。 For gdb
, it should start gdb
prompt, which you can escape by typing Quit
in gdb
prompt. gdb
,它应该启动gdb
提示符,您可以通过在gdb
提示符下键入Quit
来转义它。 File > New > C/C++ Project
File > New > C/C++ Project
Next>
. Next>
。 Cygwin GCC
in toolchain: Cygwin GCC
: src
to new source folder. src
给新的源文件夹。 HelloWorld.c
: HelloWorld.c
: Run as > Local C/C++ Application
. Run as > Local C/C++ Application
。 It should run the executable generated in earlier step. The eclipse version I ran is Photon(4.8). 我运行的eclipse版本是Photon(4.8)。 I am running cygwin64 version 2.10.0(0.325/5/3).
我正在运行cygwin64版本2.10.0(0.325 / 5/3)。
I created a new directory - foo - and added the following files in it: 我创建了一个新目录 - foo - 并在其中添加了以下文件:
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”。
#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 . cmake。
I then opened eclipse. 然后我打开了日食。
File->Import C/C++->Existing Code as Makefile Project 文件 - >导入C / C ++ - >现有代码作为Makefile项目
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" 现在在“Project Explorer”窗格中,右键单击“foo”并转到“Properties”
Go to "C/C++ Build" 转到“C / C ++ Build”
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" 再次,在“Project Explorer”窗格中,右键单击“foo”并转到“属性”
Go to "C/C++ Build" 转到“C / C ++ Build”
Go to "Environment" 去“环境”
Make sure the "CYGWIN_HOME" env variable is set correctly. 确保正确设置了“CYGWIN_HOME”env变量。 The default setting is "C:\\cygwin", but this was not good for me and caused lots of problems.
默认设置为“C:\\ cygwin”,但这对我不利并导致很多问题。 In my case it was C:\\cygwin64
就我而言,它是C:\\ cygwin64
Hit "Apply and Close" 点击“应用并关闭”
Now right click on the foo project again and click "Build Project" 现在再次右键单击foo项目,然后单击“Build Project”
Under foo in the Project Pane, click main.cpp to display it. 在项目窗格中的foo下,单击main.cpp以显示它。 Set a breakpoint somewhere.
在某处设置断点。
Hit F11 点击F11
You should take the breakpoint that you had set earlier. 您应该使用之前设置的断点。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.