This guide helps you install and configure Cygwin with VS Code to compile and run C++ programs using tools like clang++, make, and git.
What You’ll Need
- Visual Studio Code
- Cygwin with
clang++org++,make, andgit - C++ extension for VS Code
Step-by-Step Instructions
1. Install Cygwin with Required Packages
- Go to the official Cygwin website:
👉 https://www.cygwin.com/ - Download the installer:
Click thesetup-x86_64.exelink to download the 64-bit setup tool. - Run the installer and follow these prompts:
- Install from Internet
- Root directory: Use the default (e.g.,
C:\cygwin64) - Local Package Directory: Choose any folder (e.g.,
C:\cygwin\packages) - Select a mirror: Pick one near your location
- Package selection (on the “Select Packages” screen):
- Expand Devel and select:
clangorgcc-g++make
- Expand Utils and select:
git
- Expand Devel and select:
- Continue with installation and click Finish when complete.
2. Add Cygwin to Your Windows PATH
To use Cygwin tools in the terminal:
- Search “Environment Variables” in the Start Menu and open it.
- Click Environment Variables…
- Under “System variables”, select the
Pathvariable and click Edit - Add the following:
C:\cygwin64\bin - Click OK to save.
To verify, open Command Prompt or Cygwin Terminal and run:
clang++ --version # or g++ --version make --version git --version
3. Install Visual Studio Code
- Download and install VS Code from:
👉 https://code.visualstudio.com - Launch VS Code
- Go to the Extensions tab (or press
Ctrl+Shift+X) - Search and install:
C/C++ by Microsoft
4. Create and Compile a C++ Program
- Open a folder for your project in VS Code:
File → Open Folder- e.g., create a folder named
CygwinCpp
- Create a file named
hello.cppand paste:
#include <iostream>
int main() {
std::cout << "Hello, Cygwin!" << std::endl;
return 0;
}
- Open a terminal in VS Code:
Terminal → New Terminal
- Compile with:
clang++ hello.cpp -o helloor if using g++:g++ hello.cpp -o hello - Run the program:
./hello
Output should be: Hello, Cygwin!
5. Optional: Add a Makefile
- Create a file named
Makefilein the same folder:
all: hello hello: hello.cpp clang++ hello.cpp -o hello clean: rm -f hello
- Then run:
make # builds hello make clean # removes executable
6. Use Git to Track Changes
git init git add hello.cpp Makefile git commit -m "Initial Cygwin C++ setup"
Summary
You now have:
- ✔️ Cygwin with C++ tools (clang++ or g++)
- ✔️ VS Code integrated with terminal and compiler
- ✔️ A working C++ program and build process
- ✔️ Git version control enabled
