C++ 配置 Eclipse CDT 以使用 g++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8467937/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:37:31  来源:igfitidea点击:

Configure Eclipse CDT to use g++

c++eclipsewindows-7cygwineclipse-cdt

提问by Igor Filippov

I have cygwin installed, and I want to use Eclipse with CDT for development under Windows 7. However, I get following error:

我已经安装了 cygwin,我想在Windows 7下使用带有 CDT 的 Eclipse 进行开发。但是,我收到以下错误:

**** Build of configuration Default for project hello_cpp ****

make all 
g++ -O2 -g -Wall -fmessage-length=0   -c -o hello_cpp.o hello_cpp.cpp
process_begin: CreateProcess(C:\cygwin\bin\g++.exe, g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp, ...) failed.
make (e=5): Access denied.

make: *** [hello_cpp.o] Error 5

**** Build Finished ****
  • I'm able to use g++ as standalone compiler.
  • cygwin /bin folder is added to path.
  • 我可以使用 g++ 作为独立编译器。
  • cygwin /bin 文件夹被添加到路径中。

After googling I found out that C:\cygwin\bin\g++.exeis a cygwin symbolic link and Windows doesn't understand it and I need to point to the g++-3 location directly. How do I do it?

谷歌搜索后,我发现这C:\cygwin\bin\g++.exe是一个 cygwin 符号链接,Windows 不理解它,我需要直接指向 g++-3 位置。我该怎么做?

回答by nowaq

I think you've done something wrong and need to start over again. Just installed Cygwin and Eclipse CDT (Indigo) on my Windows 7 and all works fine and auto-magicaly for me.

我认为你做错了什么,需要重新开始。刚刚在我的 Windows 7 上安装了 Cygwin 和 Eclipse CDT(Indigo),一切正常,并且对我来说是自动神奇的。

Here's what I did and I think you need to do:

这是我所做的,我认为您需要做的是:

  1. Get the latest Cygwin(yes, get it again! get rid of the old one just to be sure)
  2. During the installation make sure to select gcc, gcc-g++and make(I additionally installed couple of other things like gcc4, w32apibut it's optional)
  3. Start Cygwin terminal to init all configuration files, etc. See if g++ executes and close the terminal.
  4. Add C:\cygwin\bin(or wherever else you installed it) to your Environment PATHvariable
  5. Get Eclipse CDT, extract it somewhere and start it up.
  6. Go to File -> New Project -> C++ Projectand select Hello World C++ Project. You should see the Cygwin GCCin the Toolchainslist. enter image description here
  7. Create the Project, build and run it!
  1. 获取最新的Cygwin(是的,再次获取!摆脱旧的只是为了确保)
  2. 在安装过程中,请确保选择gcc,gcc-g++make(我还安装了其他一些东西,例如gcc4w32api但它是可选的)
  3. 启动 Cygwin 终端以初始化所有配置文件等。查看 g++ 是否执行并关闭终端。
  4. 添加C:\cygwin\bin(或您安装它的任何其他地方)到您的环境PATH变量
  5. 获取 Eclipse CDT,将其解压缩到某处并启动它。
  6. 前往File -> New Project -> C++ Project并选择Hello World C++ Project。您应该会Cygwin GCCToolchains列表中看到。 在此处输入图片说明
  7. 创建项目,构建并运行它!

Done!

完毕!

Build output:

构建输出:

**** Build of configuration Debug for project TestApp ****

make all 
Building file: ../src/TestApp.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestApp.d" -MT"src/TestApp.d" -o "src/TestApp.o" "../src/TestApp.cpp"
Finished building: ../src/TestApp.cpp

Building target: TestApp.exe
Invoking: Cygwin C++ Linker
g++  -o "TestApp.exe"  ./src/TestApp.o   
Finished building target: TestApp.exe

**** Build Finished ****

回答by Hieu Le Trung

You can go to

你可以去

Project Properties Page > C / C++ Build > Settings > Tool Settings

项目属性页 > C/C++ 构建 > 设置 > 工具设置

And change the command as you want. Documentation here.

并根据需要更改命令。文档在这里

回答by Sony

Refer this link, it shows how to setup eclipse for native development with ease. everything is done in eclipse except setting environment variables.

请参阅此链接,它展示了如何轻松设置 eclipse 以进行本机开发。除了设置环境变量外,一切都在 eclipse 中完成。