Eclipse CDT:正在运行的 C++ 程序未在控制台中显示任何内容!为什么?

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

Eclipse CDT : running C++ program not showing anything in the console! Why?

c++eclipseconsoleeclipse-cdt

提问by Phil

I'm running the latest version of Eclipse with CDT on Windows 64 bits with Cygwin for compiling the code.

我正在使用 Cygwin 在 Windows 64 位上使用 CDT 运行最新版本的 Eclipse 以编译代码。

My problem is that when i run any c++ software in eclipse, there is no output in the console.

我的问题是,当我在 eclipse 中运行任何 c++ 软件时,控制台中没有输出。

I have tried this:

我试过这个:

Eclipse CDT debugger does not show console

Eclipse CDT 调试器不显示控制台

and this:

和这个:

Eclipse CDT Debug console not displaying program output

Eclipse CDT 调试控制台不显示程序输出

But it does not works.

但它不起作用。

回答by mlvljr

As guys at "No Console Output (MinGW, CDT)"point out, this is probably (or at least sometimes) because Eclipse does not add PATHto MINGW\binwhen launching the executable, so:

由于人在“无控制台输出(MinGW的,CDT)”指出,这可能是(或有时至少),因为Eclipse不添加PATHMINGW\bin启动可执行文件时,那么:

In the "Environment" tag, press "New", set it as:

在“环境”标签中,按“新建”,将其设置为:

  • "Name:PATH"
  • "Value:C:\MinGW\bin"
  • “名称:路径”
  • “值:C:\MinGW\bin”

;)

;)

回答by Sheharyar

Another solution that works (other than mlvljr's) is by adding the -staticflag in:

另一个有效的解决方案(mlvljr 除外)是在以下位置添加-static标志:

Project > Properties > C/C++ Build > Settings > Tool Settings > MinGW C++ Linker > Miscellaneous > Linker Flags

项目 > 属性 > C/C++ 构建 > 设置 > 工具设置 > MinGW C++ 链接器 > 杂项 > 链接器标志

回答by Shashank Saxena

Project > Properties > C/C++ Build > Settings > Tool Settings > MinGW C++ Linker > Miscellaneous > Linker Flags (add -static)

项目 > 属性 > C/C++ 构建 > 设置 > 工具设置 > MinGW C++ 链接器 > 杂项 > 链接器标志(添加 -static)

回答by Singhak

If All above is not working then You can try this

如果以上都不起作用,那么你可以试试这个

You have to add Environment variable of this project to have the path of MinGW compiler

你必须添加这个项目的环境变量才能有MinGW编译器的路径

Goto Project->Properties->Run/Debug Settings, choose the .exe file and press Edit In the Environment tag, press New, and set it as: Name: PATH Value: C:\MinGW\bin

If you are using cygwin then Value: c:\cygwin\bin

转到 Project->Properties->Run/Debug Settings,选择 .exe 文件并按 Edit 在 Environment 标签中,按 New,并将其设置为: Name: PATH Value: C:\MinGW\bin

如果您使用的是 cygwin,则值:c:\cygwin\bin

回答by Tom

Make sure the console is allocated:

确保控制台已分配:

project properties --> Run/Debug Settings --> yours.exe --> edit --> Common --> Check 'Allocate Console'

项目属性 --> 运行/调试设置 --> yours.exe --> 编辑 --> 通用 --> 选中“分配控制台”

回答by Phil

Thanks for the answers. I have found the problem. It was a bug from Eclipse.

感谢您的回答。我找到了问题所在。这是来自 Eclipse 的错误。

I went in the Help > Check For Updates.

我进入了帮助 > 检查更新。

I installed an update and now it works!

我安装了一个更新,现在它可以工作了!

回答by eldjon

I faced this issue not long ago. Follow this linkwhich provides quite a detailed tutorial on how to setup everything. However, the console on Eclipse Mars CDT still did not show anything. After running the generated executable file from the command line i faced the following error:

不久前我遇到了这个问题。按照此链接提供有关如何设置所有内容的详细教程。但是,Eclipse Mars CDT 上的控制台仍然没有显示任何内容。从命令行运行生成的可执行文件后,我遇到以下错误:

Apparently some path was missing

显然缺少一些路径

So considering the missing path I searched for it on cygwin main folder and added to the Project Properties -> C/C++ General -> Paths and Symbols -> Includes GNU C++the path to the missing dll folder: ${CYGWIN_HOME}/usr/i686-pc-cygwin/sys-root/usr/bin. Run again the project, and the problem was solved:

因此,考虑到丢失的路径,我在 cygwin 主文件夹中搜索了它并添加到项目属性 -> C/C++ 常规 -> 路径和符号 -> 包含 GNU C++丢失的 dll 文件夹的路径:${CYGWIN_HOME}/usr/i686-pc-cygwin/sys-root/usr/bin. 再次运行项目,问题解决:

enter image description here

在此处输入图片说明

I hope this will help somebody!

我希望这会帮助某人!

回答by Daniel Cardenas

As Singhakanswered, this issue can be "fixed" on a project-by-project basis by adding a PATH environment variable to the project's Launch configuration: Project > Properties > Run/Debug Settings > (select the project executable) > Edit.. > Environment > New... (Name: PATH, Value: path/to/compiler/bin). But you'll have to do that for every project - I don't think there's a way to set it up to work for every project, at least I have not been able to.

正如Singhak 所回答的那样,可以通过将 PATH 环境变量添加到项目的启动配置中来逐个项目地“修复”此问题:项目 > 属性 > 运行/调试设置 >(选择项目可执行文件)> 编辑.. > 环境 > 新建...(名称:PATH,值:path/to/compiler/bin)。但是您必须为每个项目都这样做 - 我认为没有办法将其设置为适用于每个项目,至少我无法做到。

However, if you're running Windows and have MS Visual Studio installed, you can set the project up using Microsoft Visual C++ Toolchains instead of GCC and that should work as expected every time.

但是,如果您运行的是 Windows 并安装了 MS Visual Studio,则可以使用 Microsoft Visual C++ 工具链而不是 GCC 来设置项目,并且每次都应该按预期工作。

回答by Clarius

I think this night be connected to the order in which I installed MinGW and eclipse CDT (Helios). The solution (for me) was to go Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> MinGW C++ Linker -> Miscellaneous -> and set Linker flags to -static-libgcc -static-libstdc++. But I seem to need to do this for every project so I'm still searching for a permanent fix.

我认为今晚与我安装 MinGW 和 eclipse CDT (Helios) 的顺序有关。解决方案(对我来说)是去项目 -> 属性 -> C/C++ 构建 -> 设置 -> 工具设置 -> MinGW C++ 链接器 -> 杂项 -> 并将链接器标志设置为 -static-libgcc -static-libstdc++。但我似乎需要为每个项目都这样做,所以我仍在寻找永久修复。