使用 Eclipse 运行.exe C 代码文件

Run .exe file of C code using Eclipse

本文关键字:代码 文件 exe Eclipse 运行 使用      更新时间:2023-10-16

我用Eclipse IDE用C语言制作了一个非常简单的基本代码。

日食详细信息:

  • 面向 C/C++ 开发人员的 Eclipse IDE
  • 版本
  • :君诺服务版本2
  • 内部版本号:20130225-0426

这是代码:

#include <stdio.h>
int main( int argc, char ** argv ) {
    printf("Hello, World!n");
    return 0;
}

Eclipse中成功运行,它会在Project/Debug目录中生成.exe和.o文件。我正在尝试运行该.exe文件,但它不起作用。

Eclipse 的行为就像它运行程序非常快,然后终止它。窗口出现,但运行.exe时没有任何反应。它看起来就像一个对话框的闪光。

应该是什么问题?我不想更改IDE,我已经尝试了以下两件事:

  • Eclipse CDT 不会运行已编译的 exe 文件
  • Eclipse 无法运行我的 exe 文件

从命令提示符窗口运行程序。如果您只是双击exe文件..它只是运行程序并立即关闭。您将没有时间看到它。

通过导航到目录并执行./yourexefile,通过cmd窗口运行它

或者双击执行此操作的一种糟糕方法是这样做:

#include <stdio.h>
int main( int argc, char ** argv ) {
   int n;
   printf("Hello, World!n");
   scanf("%d",&n); // this will force the execution window to stay open until you put in some input
   return 0;
}

您还可以执行以下操作:

#include <stdio.h>
#include <stdlib.h>
int main( int argc, char ** argv ) {
   printf("Hello, World!n");
   system("pause");
   return 0;
}

另一种方式(更美观):

#include <stdio.h>
int main( int argc, char ** argv ) {
   printf("Hello, World!n");
   printf(" Press enter to exitn");
   getchar();
   return 0;
}

Windows 正在打开程序的命令提示符,运行 print 语句,然后关闭窗口(因为函数已结束)。

如果要查看程序的结果,请运行命令提示符,导航到.exe文件的目录,然后从那里运行它。

你也应该试试这个:

在"项目资源管理器"视图中右键单击项目名称,然后转到"运行方式"并单击"本地 C/C++ 应用程序

"