使用C#或C在Windows 10上的Bash上运行GCC

我想用C#或C在bash上运行gcc,所以我可以为它做一个小IDE.我试着用cmd运行gcc:bash gcc –version(–version只是一个例子)但它显示错误:/usr/bin/gcc:/usr/bin/gcc:无法运行文件

所以我想我需要在C#或C中使用特定命令?或者我可以以某种方式直接在bash上运行gcc?

最佳答案
您需要确保在Bash中安装了gcc,然后才能从Bash或Windows调用它.

一个简单的方法是安装build-essential伪包,它将引入GCC / G和许多其他常用的开发工具,库等:

$sudo apt-get install build-essential

完成此操作后,从Bash中运行gcc –version以确保它可以访问:

$gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

现在你应该能够从cmd / PowerShell / CreateProcess / Process.Create()/ etc调用gcc:

C:\> bash -c "gcc --version"
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

HTH

转载注明原文:使用C#或C在Windows 10上的Bash上运行GCC - 代码日志