在Windows 10上使用c#或c++在Bash上运行GCC

Run GCC on Bash on Windows 10 with C# or C++

本文关键字:c++ GCC Bash 运行 Windows      更新时间:2023-10-16

我想用C#C++bash上运行gcc,所以我可以为它做一点IDE。我试图运行gcc与cmd: bash gcc --version(——版本只是一个例子),但它显示了错误:/usr/bin/gcc: /usr/bin/gcc: Can't run the file

所以我想我需要一个特定的命令在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

我建议在您的系统上安装Cygwin

bash shell是Cygwin支持的众多shell之一