无法在Eclipse中创建gcc可执行文件 [英] Cannot create gcc executable in Eclipse

查看:157
本文介绍了无法在Eclipse中创建gcc可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Eclipse中开发Java程序.我需要在此Java程序中编译输入C文件.所以我用了下面的代码.

I am developing a Java program in Eclipse. I need to compile a input C file in this Java program. So I used the below code.

Process process = Runtime.getRuntime().exec(new String[]{
     "C:/cygwin/bin/bash", 
     "-c", 
     "/usr/bin/gcc /cygdrive/d/MyFile.c -o /cygdrive/d/MyExe"});


我也安装了Cygwin.但是我无法通过执行上述代码来创建MyExe.exe.

在gcc命令旁边插入"-c"会成功创建目标文件(MyExe.o).另外,当我在Eclipse外部运行该程序(使用命令提示符)时,它会正确创建.exe.

有人可以告诉我这段代码有什么问题吗?


I have installed Cygwin as well. But I could not create MyExe.exe from executing above code.

Inserting "-c" next to gcc command successfully creates object file (MyExe.o). Also when I run this program outside Eclipse (using command prompt) it creates .exe correctly.

Can somebody tell me what is the wrong with this code?

推荐答案

我很确定这是因为您正在尝试混合两种方法来传递exec()的参数.
试试这个:
I''m pretty sure it''s because you are trying to mix two ways of passing the arguments to exec().
Try this:
Process process = Runtime.getRuntime().exec(new String[]{
"C:/cygwin/bin/bash",
"-c /usr/bin/gcc",
"/cygdrive/d/MyFile.c",
"-o /cygdrive/d/MyExe"});

Process process = Runtime.getRuntime().exec(
"C:/cygwin/bin/bash -c /usr/bin/gcc /cygdrive/d/MyFile.c -o /cygdrive/d/MyExe");



干杯,
彼得



Cheers,
Peter


这篇关于无法在Eclipse中创建gcc可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆