eclipse 内部生成器:无法运行程序“g++”:系统找不到指定的文件

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

Internal Builder: Cannot run program "g++": The system cannot find the file specified

eclipsecygwineclipse-cdt

提问by Rupali

****** Internal Builder is used for build               ******
g++ -ot1.o ..\t1.cpp
Internal Builder: Cannot run program "g++": The system cannot find the file specified.

Build error occurred, build is stopped

I am new to eclipse, on windows XP, want to run c/c++ progms + linux build (cygwin is installed with needed packages)
Above said error is coming and builds fails! Please kindly suggest.

我是 Eclipse 新手,在 Windows XP 上,想运行 c/c++ progms + linux build(cygwin 安装了所需的包)
上面说的错误即将到来,构建失败!请建议。

Edit: appends to path env variable as e:\cygwin\bin;

编辑:附加到路径环境变量作为 e:\cygwin\bin;

This is for ref:

这是参考:

alt text

替代文字

回答by VonC

How did you setup your Cygwin toolchain in your Eclipse CDT?
(from the Alex Wu's excellent blog post in Alex's Tech Blog)

您是如何在 Eclipse CDT 中设置 Cygwin 工具链的
(摘自Alex's Tech Blog 中Alex Wu的优秀博文)

1/ Install the Cygwin properly, you need following packages:

1/正确安装Cygwin,你需要以下包:

binutils
gcc
gcc-core
gcc-g++
gcc-mingw-core
gcc-mingw-g++
make
gdb (needed if you want to support debug in eclipse)

you can check your cygwin installation using the 'cygcheck -c' command

您可以使用“ cygcheck -c”命令检查您的 cygwin 安装

alt text

替代文字

2/ Add %cygwin%\binto your env PATH, then open the eclipse. you will find the cygwin tool chain will be shown when you open a new c/cpp project wizard.

2/ 添加%cygwin%\bin到您的 env PATH,然后打开 eclipse。当您打开一个新的 c/cpp 项目向导时,您会发现 cygwin 工具链将显示出来。

alt text

替代文字

3/ Configure the GDB.

3/ 配置 GDB。

Go to Windows->Preference->C/C++ -> Debug -> Common Source Lookup.
Add following 'Path mapping':

Windows->Preference->C/C++ -> Debug -> Common Source Lookup
添加以下“路径映射”:

\cygdrive\c -> c:\
\cygdrive\d -> d:\ 
other drives if any .......

alt text

替代文字

回答by donf

I just ran into the same error; it was my first time using eclipse with cygwin. I am fairly new to eclipse as well but I was impressed with how powerful it was. It is unfortunate that this question was asked almost a year ago. In the interim, the software may have changed so much that my advice below may be something of an anachronism as far as this question is concerned.

我刚刚遇到了同样的错误;这是我第一次在 cygwin 中使用 eclipse。我对 eclipse 也很陌生,但它的强大功能给我留下了深刻的印象。不幸的是,这个问题是在将近一年前提出的。在此期间,软件可能发生了很大变化,就这个问题而言,我下面的建议可能有些不合时宜。

I am using Eclipse IDE for C/C++ Developers Helios Service Release 2 version 1.3.2.20110218-0812

我正在使用 Eclipse IDE for C/C++ Developers Helios Service Release 2 版本 1.3.2.20110218-0812

uname says that the Cygwin version is CYGWIN_NT-6.1-WOW64

uname 说 Cygwin 版本是 CYGWIN_NT-6.1-WOW64

After following the (often obsolete) advice of many web posts on this issue, two things finally seemed to make it work. My sysadmin, who alone has privileges to perform software installations, needed to increase my access privileges to the cygwin/bin folder, which now stands as Read and Execute. Second, in eclipse I changed the type of builder to External: File>Properties C/C++ Build, Builder type: External builder. Build now works, though not without throwing some warnings. I am still confused about many of the intricacies of the installation, and I'm not sure why switching to an external builder made such a difference.

在遵循了许多关于这个问题的网络帖子的(通常是过时的)建议之后,有两件事似乎终于让它起作用了。我的系统管理员,只有他有权执行软件安装,需要增加我对 cygwin/bin 文件夹的访问权限,该文件夹现在是读取和执行。其次,在eclipse中我将builder的类型改为External:File>Properties C/C++ Build,Builder类型:External builder。构建现在可以工作,但并非没有抛出一些警告。我仍然对安装的许多复杂性感到困惑,我不确定为什么切换到外部构建器会产生如此大的不同。

回答by eel ghEEz

I agree with @pajton one needs to correct Eclipse's expectation of the Cygwin binary path from c:\cygwin\usr\binto c:\cygwin\binas Cygwin authors changed to mounting /usr/bin off the latter.

我同意@pajton一个需要Cygwin的二进制文件路径的正确Eclipse的预期从c:\cygwin\usr\binc:\cygwin\bin作为Cygwin的作者改为安装在/ usr / bin中关闭了后者。

I needed to change the Eclipse's addition of the Cygwin binary directory to PATH from c:\cygwin\usr\binto c:\cygwin\binin two configuration locations of my developer build Juno 20120322-1740:

我需要更改从Eclipse的另外Cygwin的二进制文件目录到PATH的c:\cygwin\usr\binc:\cygwin\bin我的开发版本朱诺20120322-1740的两个配置的位置:

  • Project Properties / C/C++ Build / Environment

  • Run / Run Configurations... / Environment

  • 项目属性/C/C++ 构建/环境

  • 运行/运行配置.../环境

I also changed the path to a shell interpreter in the discovery option Compiler invocation commandfrom shto c:\cygwin\bin\dash.exe,

我还将发现选项中的 shell 解释器的路径Compiler invocation commandshto 更改为c:\cygwin\bin\dash.exe

  • Project Properties / C/C++ Build / Discovery Options / Cygwin C Compiler

  • Project Properties / C/C++ Build / Discovery Options / Cygwin C++ Compiler

  • 项目属性/C/C++ 构建/发现选项/Cygwin C 编译器

  • 项目属性/C/C++ 构建/发现选项/Cygwin C++ 编译器

This allowed to automatically populate include directories and built-in macros in Project Properties / C/C++ General / Paths and Symbols.

这允许在项目属性/C/C++ 常规/路径和符号中自动填充包含目录和内置宏。

Because only Cygwin-built programs such as bash.exe, dash.exeresolve Cygwin-style portable symbolic links, I changed compiler invocation commands from gccto gcc-4and from g++to g++-4,

因为只有 Cygwin 构建的程序,例如bash.exe,dash.exe解析 Cygwin 风格的可移植符号链接,我将编译器调用命令从gcctogcc-4和 fromg++更改为g++-4

  • Project Properties / C/C++ Build / Settings / Tool Settings / Cygwin C++ Compiler

  • Project Properties / C/C++ Build / Settings / Tool Settings / Cygwin C Compiler

  • Project Properties / C/C++ Build / Settings / Tool Settings / Cygwin C++ Linker

  • 项目属性/C/C++ 构建/设置/工具设置/Cygwin C++ 编译器

  • 项目属性/C/C++ 构建/设置/工具设置/Cygwin C 编译器

  • 项目属性/C/C++ 构建/设置/工具设置/Cygwin C++ 链接器

Perhaps, this will be done automatically soon as I see a change in the git repository claiming to address the issue,

也许,当我看到 git 存储库中声称解决该问题的更改时,这将自动完成,

As I investigated my issue, I went to Help / Install New Software... / Juno / Programming Languages / C/C++ Development Tools.

在调查我的问题时,我转到了帮助/安装新软件.../Juno/编程语言/C/C++ 开发工具。

As I tried to upgrade the selected piece I got an unclear message saying that the requested upgrade was required by other parts. When I pressed "Finish", I received a prompt to restart. I do not know if I upgraded my CDT with these actions.

当我尝试升级所选部件时,我收到一条不清楚的消息,说其他部件需要请求的升级。当我按下“完成”时,我收到了重新启动的提示。我不知道我是否通过这些操作升级了我的 CDT。

If you want to catch access violations at run time, create an external tool entry in Run / External Tools... / Configure External Tools. Specify c:\cygwin\bin\bash.exeas the program, ${workspace_loc:/PROJECT_NAME/CONFIG_NAME}such as ${workspace_loc:/test/Release}as the working directory and the command option followed by the program name such as -c "./test.exe"in the arguments. I found that c:\cygwin\bin\dash.exedoes not route the stack trace produced by the Cygwin DLL to the stderr caught by Eclipse.

如果要在运行时捕获访问冲突,请在运行/外部工具.../配置外部工具中创建一个外部工具条目。指定c:\cygwin\bin\bash.exe为程序,${workspace_loc:/PROJECT_NAME/CONFIG_NAME}例如${workspace_loc:/test/Release}工作目录和命令选项,后跟程序名称,例如-c "./test.exe"在参数中。我发现它c:\cygwin\bin\dash.exe不会将 Cygwin DLL 生成的堆栈跟踪路由到 Eclipse 捕获的 stderr。

回答by Chris Genly

Another way to fix this is to go to

解决这个问题的另一种方法是去

project properties / c/c++ build / settings / tool settings / cygwin C compiler

and change the command to

并将命令更改为

sh -c 'whatever was already there'

This will use shto invoke the command, and thus it will resolve cygwin links. You will also have to do this for the assembler and linker. Of course you also have to make sure your path points to c:\cygwin\bin before starting eclipse.

这将使用sh来调用命令,因此它将解析 cygwin 链接。您还必须为汇编器和链接器执行此操作。当然,在启动 eclipse 之前,您还必须确保您的路径指向 c:\cygwin\bin。