dev_tool_tutorials

Tutorials on common developer tools for computer science students.


Project maintained by jeremyglebe Hosted on GitHub Pages — Theme by mattgraham

Using Cygwin With Your C++ VSCode Dev Environment

Subject

Once you’ve already set up your VSCode environment on Windows you may find yourself feeling like MinGW wasn’t enough to bridge the Windows-GNU gap. If you need more GNU features so that you and your Linux/MacOS friends can both run the same code, you might consider installing Cygwin. Where MinGW just ports a few GNU tools over to Windows, Cygwin creates an entirely new environment on your system. In essence, when you compile with Cygwin you aren’t considered to be using Windows. You are considered to be using the Unix-like Cygwin platform. This is very helpful, but there is a setup process.

Requirements

The following is assumed about your environment:

Install Cygwin

Using Cygwin Terminal in VSCode

Cygwin has its own built-in terminal, and all your handy GNU features are only available in that terminal. So how can we get this terminal to be used in VSCode? We have two methods. I will explain here how to make Cygwin your default terminal. However, I don’t actually recommend that. I will be writing a separate tutorial on how to use different terminals in VSCode. If you follow that tutorial, you can avoid making Cygwin your default (which would not be preferable in all situations) and instead just use it when needed. If you want to proceed with making it your default terminal, follow the steps below:

Open Cygwin in a folder?

Do you want to be able to open your Cygwin terminal in any folder (easily)? You can set up a right-click menu option to open the terminal. (That menu is called the “context menu”) To add Cygwin’s terminal to the context menu, follow the advice on this Stack Overflow page. Don’t want to follow the link? That’s okay. It is really easy. Here’s the important part:

After Cygwin is launched, open up a Cygwin terminal (as an administrator)
and type the command:
chere -i -t mintty -s bash.
Now you should have "Bash Prompt Here" in the Windows right-click context menu.

Conclusion

That’s it! Cygwin should now work in your existing VSCode environment. Using Run Code should now use Cygwin’s build tools. I really really recommend running Cygwin not as your default terminal, but as on of many using the Shell Launcher extension. This will cause problems with Code Runner (CR will only use the default terminal) but these problems will be addressed in the Shell Launcher tutorial.