使用 MinGW 的 Eclipse CDT 不在控制台中输出

发布于 2024-09-13 22:32:19 字数 1009 浏览 7 评论 0原文

我有一台 Windows 7 64 位 PC,并且正在尝试安装免费的 C++ IDE,因此我选择使用 CDT 安装 Eclipse Helios。

对于 g++、make 和 gdb,我根据本教程安装了 msys 和 mingw: http://wiki.wxwidgets.org/HowTo:_Install_MSYS_and_MinGW_for_use_with_Eclipse_CDT

版本为:

  • make:GNU make 3.81
  • g++: 4.5.0
  • gdb: 7.1

所以它应该与我的 64 位 CPU 兼容。

然而,当我尝试使用 Eclipse 运行一个非常简单的程序时,我在控制台上看不到任何内容。源代码是:

#include <iostream>

 using namespace std;

 int main()
 {
    int i;

    cout << "Enter an integer: " << endl;
    cin >> i;
    cout << endl << "i is " << i << endl;

    return 0;
 }

构建很好,当我使用命令(Windows 控制台)启动 .exe 时,行为符合预期。 但是使用 Eclipse 控制台,我在运行时看不到任何内容,而在调试时,输出只是: “输入一个整数:”,然后当我输入一个数字并按 Enter 键时,它什么也不做。

有人知道如何解决这个问题吗?

谢谢,

Guillaume

PS:我使用工具链“Linux GCC”,使用“MinGW GCC”我在控制台中什么也没有。

I have a Windows 7 64-bit PC and I am trying to install a free C++ IDE, so I chose to install Eclipse Helios with CDT.

For g++, make and gdb I installed msys and mingw according to this tutorial:
http://wiki.wxwidgets.org/HowTo:_Install_MSYS_and_MinGW_for_use_with_Eclipse_CDT

The versions are:

  • make: GNU make 3.81
  • g++: 4.5.0
  • gdb: 7.1

So it should be compatible with my 64-bit CPU.

However when I try to run a very simple program with eclipse, I see nothing on the console. The source code is:

#include <iostream>

 using namespace std;

 int main()
 {
    int i;

    cout << "Enter an integer: " << endl;
    cin >> i;
    cout << endl << "i is " << i << endl;

    return 0;
 }

The build is fine and when I launch the .exe with command (windows console) the behavior is as expected.
But with the Eclipse console I see nothing with run and with debug the output is just:
"Enter an integer: ", then when I type in a number and hit enter it does nothing.

Does anyone know how to fix this please?

Thanks,

Guillaume

PS: I use the toolchain "Linux GCC", with "MinGW GCC" I have nothing at all in the console.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

守望孤独 2024-09-20 22:32:20

您需要设置链接器
我正在使用 MinGW。

请按照以下步骤操作。

Goto Project > Properties > C/C++ Build > Settings > Tool Settings (Tab) > MinGW C++ Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++)   (default command is only g++)

You need to set up linker
I am using MinGW.

Follow below steps.

Goto Project > Properties > C/C++ Build > Settings > Tool Settings (Tab) > MinGW C++ Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++)   (default command is only g++)
痞味浪人 2024-09-20 22:32:20

purlogic 的解决方案有效。
我发现它可以全局设置,而不是为每个项目设置它:

在窗口 ->首选项-> C/C++->构建->环境
为您的编译器添加一个变量。例如,我补充道:
MINGW,值为“C:\MinGW\bin”

purlogic's solution works.
Instead to set that for every project, I found it can be set globally:

In Window -> Preferences-> C/C++ -> Build -> Environment
Add a variable for your compiler. e.g, I added:
MINGW, with value "C:\MinGW\bin"

心凉 2024-09-20 22:32:20

在 64 位版本的 eclipse 中已注意到此控制台错误:

http://www.eclipse.org/forums/index.php?t=msg&th=197552&start=0&S=2a2b64e1f1404705c0214976bd477428

解决方法是安装 32-点蚀

This console bug has been noticed in 64-bit versions of eclipse:

http://www.eclipse.org/forums/index.php?t=msg&th=197552&start=0&S=2a2b64e1f1404705c0214976bd477428

A workaround is to install the 32-bit eclipse

恰似旧人归 2024-09-20 22:32:20

我遇到了同样的问题,因为在一台 PC 上安装了多个 gcc。但格雷格的解决方案只对我有用。

就我而言,刷新并未在应用程序中明确完成。而 C++ 程序经常使用 std::cout << ...<< std::endl 其中 endl 进行刷新,我的程序使用实际的 C 输出,例如通常的 printf。在cmd窗口中启动程序时可以直接看到printf。然而在 Eclipse 控制台中它们丢失了。因此,

fflush(stdout);

printf 为我完成了这件事之后。这可能是 eclipse 控制台实现中的一个问题。我想这就是为什么修复路径对这里的某些人不起作用。

另一种解决方案不是在“运行”设置中设置 PATH,而是使用批处理文件启动整个 Eclipse,其本质上如下所示:

set PATH=<mymingwlocation>\bin;%PATH%
start <myeclipselocation>\eclipse.exe

然后,任何运行配置都将默认使用正确的 MingW 位置。这还可能解决因使用错误的 gcc 而可能出现的其他问题。

I ran into the same problem, because of multiple gcc installations on one PC. But Greg's solution only worked partly for me.

In my case the flush was not done in the application explicitly. While C++ programs often use std::cout << ... << std::endl where the endl does a flush, my program used actual C-output such as the usual printf. The printf could be seen directly when starting the program in the cmd-window. However in eclipse console they were missing. Hence a

fflush(stdout);

after the printf did the thing for me. That could be an issue within the eclipse console implementation. I guess that's why fixing the Path did not work for some people here.

An alternative solution instead of setting the PATH within the "Run" settings is to start the whole eclipse using a batch file, which looks essentially like this:

set PATH=<mymingwlocation>\bin;%PATH%
start <myeclipselocation>\eclipse.exe

Then any run configuration would use the correct MingW location by default. That might also fix other problems that could arise from using the wrong gcc.

可爱咩 2024-09-20 22:32:20

您是否尝试过以管理员权限执行 eclipse.exe ?它对我有用!

Have you tried to execute the eclipse.exe with administrator privileges ?? it worked for me !

窗影残 2024-09-20 22:32:20

在 64 位/32 位 eclipse Kepler CDT 上遇到此问题,以便在 openCV/wxWidgets 工具 Win7 上使用 MinGW 构建。

如果有人在使用 openCV 时遇到此问题,您就会知道互联网上有许多过时的 openCV 构建/安装说明。

我的一个方法是转到“构建设置”->“构建设置”。链接器->在“杂项”和“链接器标志”文本输入框中,输入
-Wl,--子系统,windows -mwindows
但是,这会禁用 cout 输出到 Windows 中的命令行终端。

进一步挖掘这看起来是故意的,显然 -mwindows 涉及将 STDOUT 从命令行专门定向到类似 GUI 的应用程序。

另外,删除 -mwindows 并保留 -Wl,--subsystem,windows 仍然可以完成将 STDOUT 重定向到远离命令行的任务。

现在请注意,除了涉及 wxWidgets 和 openCV 的 hello world 程序之外,我还没有构建任何东西,所以我还没有到对 GUI 的一部分进行 cout 的阶段,所以我不知道该功能是否会现在被破坏了或者它是否会打印到 GUI 对象以及命令行终端。

Had this issue on 64-/32-bit eclipse Kepler CDT to work on a openCV/wxWidgets tool, Win7, using MinGW to build.

If anyone comes across this while having this issue and are working with openCV you will already know that there are many outdated openCV building/installing instructions all over the internet.

One I had was to go to Build Settings -> Linker -> Miscellaneous and inside of the Linker Flags text entry box, type in
-Wl,--subsystem,windows -mwindows
However, this disables cout from outputting to a command line terminal in windows.

Doing some more digging this looks intentional, apparently the -mwindows involves directing STDOUT away from a command line specifically to a GUI-like application.

Also, removing -mwindows and just leaving in -Wl,--subsystem,windows accomplishes the task of redirecting STDOUT anyway away from the command line all the same.

Now mind you, I haven't built up anything yet outside of a hello world program involving wxWidgets and openCV, so I am not at the point of doing a cout into a part of a GUI so I don't know if that functionality would now be broken or if it would print out to the GUI object, as well as a command line terminal.

猥︴琐丶欲为 2024-09-20 22:32:20

通过 Run -> 添加 PATH 变量(PATH=“你的 MinGW/bin 目录路径”)到你的 C++ 项目中。运行配置 -> 在环境选项卡

在此处输入图像描述

Add PATH variable (PATH="your MinGW/bin directory path") into your C++ project by Run -> Run Configurations ->in Environment Tab

enter image description here

ぃ双果 2024-09-20 22:32:20

或者设置链接器选项-static
至少对我有用。

Or set the linker option -static.
Works for me at least.

相权↑美人 2024-09-20 22:32:19

这对我使用 MinGW 在 Windows 7 上安装 64 位 Eclipse 很有用:

右键单击您的项目。选择“属性”。

选择新窗口左侧的“运行/调试设置”属性。

在右侧窗口中,单击突出显示的可执行文件(即 Test.exe),然后单击“编辑”。

在“环境”选项卡中,点击“新建”

名称:PATH
值:MinGW bin 目录的路径。 (对我来说,这是:C:\devcore\MinGW\bin

在所有窗口上单击“确定”关闭。

再次尝试运行,它应该将输出打印到屏幕上。

This worked for me on 64-bit install of Eclipse on Windows 7 using MinGW:

Right-click on your project. Select "Properties".

Select the "Run/Debug Settings" Property on the left of the new window.

In the right window, click on your executable to highlight (ie - Test.exe) and click "Edit".

In the Environment tab, hit "New"

Name: PATH
Value: Path to your MinGW bin directory. (For me this was: C:\devcore\MinGW\bin)

Click "OK" on all windows to close down.

Try running again, it should print output to the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文