简体   繁体   中英

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

I want to run gcc on bash with C# or C++ so I can make a little IDE for it. I tried to run gcc with cmd: bash gcc --version (--version is just a example) but it shows the error: /usr/bin/gcc: /usr/bin/gcc: Can't run the file

So i guess i need a specific command in C# or C++ ? Or can i somehow run gcc on bash directly?

You need to ensure you've got gcc installed in Bash before you can invoke it from Bash or from Windows.

An easy way to do this is to install build-essential pseudo-package which will bring in GCC/G++ and a host of other commonly required dev tools, libs, etc:

$ sudo apt-get install build-essential

Once you've done this, run gcc --version from within Bash to make sure it's reachable:

$ 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.

Now you should be able to invoke gcc from cmd/PowerShell/CreateProcess/Process.Create()/etc:

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

I recommend installing Cygwin on your system

The bash shell is one of many supported by Cygwin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM