Eclipse CDT 控制台输出没有在带路径的调试中显示,也没有在没有路径的运行中显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9528523/
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
Eclipse CDT Console output not showing up in debug with path and not showing up in run without path
提问by gsingh2011
I'm trying to get Eclipse CDT (64 bit eclipse) working on Windows 7 with GCC. When I first got GDB working (that was a challenge in itself), running the program in debug mode was the only way I got output. Running it normally didn't give any console output. After hours of googling, I figured out that if I added C:/cygwin/bin to my environment path in eclipse, I could get output when running the program normally. Then I ran it in debug mode and there was no output. I tested this a couple of times to make sure it was the addition of the path causing the problem. This is the program I was running,
我正在尝试使用 GCC 在 Windows 7 上运行 Eclipse CDT(64 位 Eclipse)。当我第一次让 GDB 工作时(这本身就是一个挑战),在调试模式下运行程序是我获得输出的唯一方式。通常运行它不会给出任何控制台输出。经过几个小时的谷歌搜索,我发现如果我在eclipse中将C:/cygwin/bin添加到我的环境路径中,我可以在正常运行程序时得到输出。然后我在调试模式下运行它,没有输出。我对此进行了几次测试,以确保它是导致问题的路径的添加。这是我运行的程序
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
So how can I get both normal and debug modes working, and why did I have to include that path in the first place (it's already in my cygwin path and why does CDT need it?) ? Also, why is it that if I add a path to my Run configurations it will also be added to my Debug configurations?
那么如何让正常模式和调试模式都工作,为什么我必须首先包含该路径(它已经在我的 cygwin 路径中,为什么 CDT 需要它?)?另外,为什么如果我将路径添加到我的运行配置中,它也会被添加到我的调试配置中?
回答by infoartenovo
From wiki eclipse: In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windows console, but to a pipe. See bug 173732for more details. Either add flush calls after every printf or add the following lines at the start of the main function:
来自wiki eclipse:在 Windows 上的 Eclipse CDT 中,正在运行或调试的程序的标准输出是完全缓冲的,因为它没有连接到 Windows 控制台,而是连接到管道。有关更多详细信息,请参阅错误 173732。要么在每个 printf 之后添加刷新调用,要么在主函数的开头添加以下几行:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
回答by Mike G
I don't think I can answer everything but I use exactly the same set-up as you and I've had to deal with quite a few issues like this (I'm wondering if you had trouble how to juggle using the 32-bit/64-bit JVM and Internet browsing)!
我不认为我可以回答所有问题,但我使用的设置与您完全相同,而且我不得不处理很多这样的问题(我想知道您是否在使用 32-位/64 位 JVM 和 Internet 浏览)!
The cygwin/bin path must be specified because that is where gcc, gdb and all the other cygwin tools and dlls are located (I'll assume you're using cygwin flavour of gcc rather than MinGW flavour). I believe you must specify it in the Windows environment (using a win32 file path) because Eclipse is running using the Windows JVM and therefore deals with win32 paths. Consequently, it doesn't matter that cygwin/bin
is added to the PATH
variable in the cygwin environment. CDT is looking for cygwin using Eclipse, and Eclipse needs to find cygwin1.dll from Windows.
必须指定 cygwin/bin 路径,因为这是 gcc、gdb 和所有其他 cygwin 工具和 dll 所在的位置(我假设您使用的是 cygwin 风格的 gcc 而不是 MinGW 风格)。我相信您必须在 Windows 环境中指定它(使用 win32 文件路径),因为 Eclipse 使用 Windows JVM 运行,因此处理 win32 路径。因此,将其cygwin/bin
添加到PATH
cygwin 环境中的变量并不重要。CDT 正在使用 Eclipse 寻找 cygwin,而 Eclipse 需要从 Windows 中找到 cygwin1.dll。
I might be totally wrong, but if I had to guess I would say that you need to make absolutely sure you have properly set the PATH
environment variable correctly for both configurations.
我可能完全错了,但如果我不得不猜测,我会说您需要绝对确保已PATH
为两种配置正确设置了环境变量。
One thing to note is that in Eclipse there is no differencebetween a configuration shown in the Debug Configurationswindow and one with the same name in the Run Configurationswindow. The only difference between the two windows is that one will run the program without using a debugger and has tabs for setting debug settings. Therefore it's no surprise that changing settings in one will also affect the other.
需要注意的一件事是,在 Eclipse中,Debug Configurations窗口中显示的配置与Run Configurations窗口中具有相同名称的配置之间没有区别。两个窗口之间的唯一区别是,一个将在不使用调试器的情况下运行程序,并且具有用于设置调试设置的选项卡。因此,更改一个中的设置也会影响另一个也就不足为奇了。
As you may know, for many projects the build system is set up to produce two (sometimes more) sets of binaries: one with debugging info/symbols (DEBUG) and one without (RELEASE). In this case, you normally have two configurations in Eclipse: one to run the DEBUG binary and one to run the RELEASE binary. Both of these will show up in both the Debug Configurationswindow and in the Run Configurationswindow. The point is that you can run DEBUG either with or without gdb, but RELEASE cannot be used by gdb.
您可能知道,对于许多项目,构建系统设置为生成两组(有时更多)二进制文件:一组带有调试信息/符号 (DEBUG),另一组没有 (RELEASE)。在这种情况下,Eclipse 中通常有两种配置:一种用于运行 DEBUG 二进制文件,另一种用于运行 RELEASE 二进制文件。这两个都将显示在“调试配置”窗口和“运行配置”窗口中。关键是你可以在有或没有 gdb 的情况下运行 DEBUG,但 gdb 不能使用 RELEASE。
That said, I'm not sure why adding the correct path to the run configuration would stop the DEBUG binary from outputting to the console. I suspect something else is going on here, perhaps a mismatch of debug info and debugger.
也就是说,我不确定为什么将正确的路径添加到运行配置会阻止 DEBUG 二进制文件输出到控制台。我怀疑这里发生了其他事情,可能是调试信息和调试器不匹配。
To (hopefully) answer your question as to how to get both configurations working, go the whole-hog and just add C:\cygwin\bin;
to the Windows PATH
environment variable. I'm guessing that will allow both to work. I'll assume you know how to do that but please post a comment if not.
要(希望)回答有关如何使两种配置都正常工作的问题,请全力以赴并添加C:\cygwin\bin;
到 WindowsPATH
环境变量中。我猜这将使两者都能工作。我假设你知道怎么做,但如果不知道,请发表评论。
The other thing to try would be to compile and run the program from a cygwin shell. If it works there it's probably a safe bet that your PATH
environment variable is not set correctly when using eclipse.
要尝试的另一件事是从 cygwin shell 编译和运行程序。如果它在那里工作,那么PATH
使用 eclipse 时您的环境变量设置不正确可能是一个安全的赌注。
Hope that helps!
希望有帮助!
回答by Richard
Adding the Path was correct before gdb 7.3. Now when I add the path I can no longer use breakpoints as it cannot find the dll files as they are no longer part of the path. To fix this you can easily add the entire path from the environment by following these instructions.
在 gdb 7.3 之前添加路径是正确的。现在,当我添加路径时,我无法再使用断点,因为它找不到 dll 文件,因为它们不再是路径的一部分。要解决此问题,您可以按照以下说明轻松添加环境中的整个路径。
left click the project
enter the RUN/DEBUG settings for the project
select the executable
click edit
select Environment Tab
click Select...
scroll down to Path (Case sensitive)
check mark Path
press OK
press OK
press OK
You can see the dll problem as it appears in the gdb console error,msg="During startup program exited with code 0xc00000be." or error,msg="During startup program exited with code 0x00000135." and you may get an error window pop up saying it could not clear the breakpoint
您可以看到 dll 问题,因为它出现在 gdb 控制台错误中,msg="在启动期间程序退出,代码为 0xc00000be。" 或 error,msg="在启动期间程序退出,代码为 0x00000135。" 你可能会弹出一个错误窗口,说它无法清除断点
回答by Dhiral Pandya
You need to set up linker I am using MinGW.
您需要设置链接器,我正在使用 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++)
回答by cardiff space man
Don't debug or run C or C++ applications from inside Eclipse if they target Cygwin. TK link to "you're gonna have a bad time" meme.
如果 C 或 C++ 应用程序以 Cygwin 为目标,请不要从 Eclipse 内部调试或运行它们。TK 链接到“你会过得很糟糕”模因。
There are problems with Cygwin stdout/stderr that don't show up if you run the programs from the normal Cygwin console (where you would be running bash), but they do show up in pretty much every other way you can run them.
Cygwin stdout/stderr 存在一些问题,如果您从普通 Cygwin 控制台(您将在其中运行 bash)运行程序,则不会出现这些问题,但它们确实以几乎所有其他可以运行它们的方式出现。
The normal way that programs run other programs in Linux and other posix-supporting environments is to reroute the i/o to a pty. Cygwin can't support pty's 100% in Windows.
程序在 Linux 和其他支持 posix 的环境中运行其他程序的正常方式是将 i/o 重新路由到 pty。Cygwin 在 Windows 中无法 100% 支持 pty。
Some of the problems can be ameliorated by the setvbuf calls in @infoartenovo's answer.
@infoartenovo 的回答中的 setvbuf 调用可以改善一些问题。
A flip side of this problem is that applications written to use Windows' Console API don't work well in ptys.
这个问题的另一方面是编写使用 Windows 控制台 API 的应用程序在 ptys 中不能很好地工作。
We are all collateral damage in an unwinnable war.
在一场无法取胜的War中,我们都是附带损害。
http://cygwin.com/ml/cygwin/2011-12/msg00236.htmlhttps://code.google.com/p/mintty/issues/detail?id=56
http://cygwin.com/ml/cygwin/2011-12/msg00236.html https://code.google.com/p/mintty/issues/detail?id=56