DevNoteHQ
DevNoteHQ

Reputation: 303

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?

Upvotes: 4

Views: 23773

Answers (2)

Rich Turner
Rich Turner

Reputation: 10984

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

Upvotes: 11

Thomas Matthews
Thomas Matthews

Reputation: 57678

I recommend installing Cygwin on your system

The bash shell is one of many supported by Cygwin

Upvotes: 1

Related Questions