Setting Up VS Code with Cygwin for C++ on Windows 11

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++ or g++, make, and git
  • C++ extension for VS Code

Step-by-Step Instructions


1. Install Cygwin with Required Packages

  1. Go to the official Cygwin website:
    👉 https://www.cygwin.com/
  2. Download the installer:
    Click the setup-x86_64.exe link to download the 64-bit setup tool.
  3. 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
  4. Package selection (on the “Select Packages” screen):
    • Expand Devel and select:
      • clang or gcc-g++
      • make
    • Expand Utils and select:
      • git
  5. Continue with installation and click Finish when complete.

2. Add Cygwin to Your Windows PATH

To use Cygwin tools in the terminal:

  1. Search “Environment Variables” in the Start Menu and open it.
  2. Click Environment Variables…
  3. Under “System variables”, select the Path variable and click Edit
  4. Add the following: C:\cygwin64\bin
  5. 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

  1. Download and install VS Code from:
    👉 https://code.visualstudio.com
  2. Launch VS Code
  3. Go to the Extensions tab (or press Ctrl+Shift+X)
  4. Search and install:
    C/C++ by Microsoft

4. Create and Compile a C++ Program

  1. Open a folder for your project in VS Code:
    • File → Open Folder
    • e.g., create a folder named CygwinCpp
  2. Create a file named hello.cpp and paste:
#include <iostream>
int main() {
    std::cout << "Hello, Cygwin!" << std::endl;
    return 0;
}
  1. Open a terminal in VS Code:
    • Terminal → New Terminal
  2. Compile with: clang++ hello.cpp -o hello or if using g++: g++ hello.cpp -o hello
  3. Run the program: ./hello

Output should be: Hello, Cygwin!


5. Optional: Add a Makefile

  1. Create a file named Makefile in the same folder:
all: hello

hello: hello.cpp
	clang++ hello.cpp -o hello

clean:
	rm -f hello
  1. 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

Scroll to Top