This guide will walk you through the steps to compile and run a C++ program in Visual Studio Code (VSCode) using the clang++
compiler.
Before you begin, ensure that you have the following:
- Visual Studio Code installed. You can download it from here.
- clang++ installed on your system.
- macOS:
clang++
is pre-installed with Xcode Command Line Tools. Install it with:xcode-select --install
- Linux: Install
clang++
using the package manager:sudo apt install clang
- Windows: Please follow these instruction from Using GCC with MinGW.
- macOS:
- In VSCode, open the Integrated Terminal by navigating to:
- View > Terminal
- Or press
Ctrl + J
(orCmd + J
on macOS) to open the terminal.
-
In the terminal, run the following command to compile your
main.cpp
file usingclang++
:clang++ -o main main.cpp
-
This will generate an executable file named main.
-
After building the program, you can run it directly from the terminal by typing:
./main
-
You should see the following output:
Hello, World!