Step-by-step Guide – Setting up Code::Blocks, Visual Studio, and GCC for cplus tutorial

9/12/2025

Setting up Code::Blocks, Visual Studio, GCC for cplus coding

Go Back

Step-by-step Guide – Setting up Code::Blocks, Visual Studio, and GCC

Introduction

A proper development environment makes coding in C++ easier, faster, and more productive. Here’s a beginner-friendly step-by-step guide for setting up Code::Blocks, Visual Studio, and GCC, three of the most popular tools for C++ development.


 Setting up Code::Blocks, Visual Studio,  GCC for cplus coding

Setting up Code::Blocks

Code::Blocks is a lightweight and beginner-friendly IDE for C++.

Step 1 – Download

Step 2 – Install

  • Run the installer and accept the default options.

  • Code::Blocks will automatically detect and configure the included GCC compiler.

Step 3 – Verify setup

  • Open Code::Blocks → Create a new Console Project → Choose C++.

  • Add this code:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello from Code::Blocks!" << endl;
    return 0;
}
  • Press Build and Run (F9). You should see the output in the console window.


Setting up Visual Studio (MSVC)

Visual Studio is a full-featured IDE by Microsoft, best for Windows users.

Step 1 – Download

Step 2 – Install

  • Launch the installer.

  • Select "Desktop development with C++" workload.

  • Click Install and wait for the installation to complete.

Step 3 – Create and run a C++ project

  • Open Visual Studio.

  • Go to File → New → Project → choose Console App (C++).

  • Write the following code:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello from Visual Studio!" << endl;
    return 0;
}
  • Press Ctrl+F5 to build and run the project.


Setting up GCC (GNU Compiler Collection)

GCC is a compiler, not an IDE. You can use it with any text editor or terminal.

Step 1 – Install GCC

  • Windows: Install via MSYS2 or install Code::Blocks with MinGW.

  • macOS: Install Xcode Command Line Tools using xcode-select --install.

  • Linux (Ubuntu/Debian):

sudo apt update
sudo apt install build-essential -y

Step 2 – Verify installation

Open a terminal and run:

g++ --version

You should see version information.

Step 3 – Compile and run a test program

Create a file test.cpp:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello from GCC!" << endl;
    return 0;
}

Compile and run:

g++ -std=c++17 test.cpp -o test
./test

Conclusion

You’ve successfully set up Code::Blocks, Visual Studio, and GCC for C++ development. These tools give you a complete environment to build, run, and debug C++ programs across different platforms.


Step-by-step guide - Setting up Code::Blocks, Visual Studio, and GCC

Meta Description:
Step-by-step instructions to set up Code::Blocks, Visual Studio, and the GCC toolchain across Windows, macOS, and Linux. Includes project setup, common settings, verification, and troubleshooting tips.

Meta Keywords:
install Code::Blocks, setup Visual Studio C++, install GCC, MinGW, MSYS2, MSVC, g++ setup


Quick overview

This section shows practical, copy‑paste steps to get three common C++ development setups working: Code::Blocks (lightweight IDE), Visual Studio (full-featured Windows IDE), and GCC (the cross‑platform compiler toolchain). Use the method that fits your platform and workflow.


A. Code::Blocks (IDE)

Windows (recommended with MinGW bundled)

  1. Download the Code::Blocks installer that includes MinGW (look for the "with MinGW" or "mingw-setup" package) from the official Code::Blocks site.

  2. Run the installer and follow the prompts. If you chose the MinGW bundle, a GCC toolchain will be installed alongside Code::Blocks.

  3. Launch Code::Blocks. Go to Settings → Compiler to confirm the selected compiler is GNU GCC Compiler.

  4. In Settings → Compiler → Toolchain executables verify the path to g++/gcc. Click Auto-detect or point it to the MinGW bin folder (for example C:\Program Files\CodeBlocks\MinGW\bin or your MSYS2 MinGW path).

  5. Create a new project: File → New → Project → Console Application → C++. Follow the wizard and choose the GNU GCC compiler when prompted.

  6. Add your source (main.cpp), then Build → Build and Run (or press F9). If compilation succeeds you’ll see program output in the console window.

Linux

  • Install Code::Blocks from your distro package manager (e.g., sudo apt install codeblocks on Debian/Ubuntu) or from the official download. Ensure g++ is installed (sudo apt install build-essential).

  • Open Code::Blocks and follow the same project wizard described above.

macOS

  • Code::Blocks is available as a download from the official site. Alternatively install via your package manager if available. On macOS you’ll usually pair Code::Blocks with Clang (Xcode tools) or a Homebrew-installed GCC.

Common Code::Blocks troubleshooting

  • "Compiler not found": re-check Toolchain executables path and ensure g++ exists there.

  • Linker errors (undefined reference): ensure correct source files are part of the project and you build the project (not just individual files).


B. Visual Studio (Windows)

Install and initial setup

  1. Download the Visual Studio Community installer from Microsoft.

  2. During installation select the "Desktop development with C++" workload. Optionally include CMake, Clang tools, and the Windows SDK.

  3. Finish install and launch Visual Studio.

Create and run a simple C++ project

  1. File → New → Project. Search/select Console App (C++). Choose an empty console or the default template.

  2. Name the project and solution, then click Create.

  3. Right-click Source Files → Add → New Item → C++ File (.cpp), name it main.cpp, and paste your code.

  4. Build with Build → Build Solution (Ctrl+Shift+B). Run with Debug → Start Debugging (F5) or Start Without Debugging (Ctrl+F5).

Important Visual Studio settings

  • Change the active configuration (Debug/Release) and platform (x86/x64) from the toolbar.

  • Set the language standard: Project Properties → C/C++ → Language → C++ Language Standard (e.g., ISO C++17 or Default).

  • Add include directories and linker inputs in Project Properties → VC++ Directories and Linker sections.

Using CMake and vcpkg

  • Visual Studio has built-in CMake project support and integrates with vcpkg for dependency management — good for cross-platform projects.

Troubleshooting

  • If cl or MSVC tools are not found, open the Developer Command Prompt for Visual Studio to confirm the environment is set, or ensure the workload with C++ tools was installed.


C. GCC (Toolchain) — Windows / macOS / Linux

Windows (MSYS2 + MinGW-w64 recommended)

  1. Install MSYS2 from the official MSYS2 website (then use the MSYS2 MinGW 64-bit shell for 64-bit builds).

  2. Update packages in the MSYS2 shell:

pacman -Syu
# close and re-open the shell when prompted
pacman -Su
  1. Install the mingw-w64 toolchain:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain
  1. Verify:

g++ --version
  1. Compile a program:

g++ -std=c++17 -Wall -Wextra hello.cpp -o hello.exe
./hello.exe

macOS (Homebrew or Xcode toolchain)

  • You can use Apple's Clang (installed via xcode-select --install) or install GNU GCC via Homebrew: brew install gcc (binaries appear as g++-<version>).

  • Verify with g++ --version or g++-<version> --version and compile using the appropriate executable.

Linux (Debian/Ubuntu example)

sudo apt update
sudo apt install build-essential gdb -y

g++ --version
g++ -std=c++17 -Wall -Wextra hello.cpp -o hello
./hello

Simple Makefile example

CXX = g++
CXXFLAGS = -std=c++17 -Wall -O2

all: main

main: main.o
	$(CXX) $(CXXFLAGS) -o $@ $^

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -f *.o main

GCC troubleshooting

  • g++: command not found: ensure the toolchain is installed and the bin folder is in your PATH.

  • Version mismatch: on macOS g++ may be Apple Clang. Use g++-<version> for Homebrew GCC.


D. Integrating GCC with IDEs

  • Code::Blocks: set the compiler path in Toolchain executables to the directory containing g++.exe.

  • Visual Studio: you can use CMake to build with GCC on WSL or use Visual Studio’s Linux development workload to target GCC on remote Linux/WSL systems.


E. Recommended quick settings & tips

  • Always compile with warnings enabled: -Wall -Wextra.

  • Use -std=c++17 or newer depending on your needs (-std=c++20).

  • For debugging memory issues enable sanitizers: -fsanitize=address,undefined (GCC/Clang).

  • Use CMake for cross-platform builds and dependency management.


F. Final notes

Pick Visual Studio for heavy Windows-native development, Code::Blocks if you want a lightweight GUI IDE, and GCC for flexible cross-platform builds. Combine the tools (e.g., Code::Blocks + MinGW, Visual Studio + CMake) to match your project's needs and target platforms.

Table of content