Setting up the development environment for C/C++
26 August 2024
Author - @Bibhabendu Mukherjee
Steps to setup c/c++ development environment.
Setting up a development environment for C programming is essential to ensure smooth code writing, compilation, and debugging. It provides the necessary tools, like a compiler and IDE, to transform code into executable programs. A proper setup boosts productivity and minimizes errors, allowing developers to focus on learning and building projects efficiently.
Step-by-Step Setup
The first thing that you need to do is to install the c/c++ compiler.compiler is a software or program that understand c/c++ syntax and help it to execute on your machine.
Popular Compilers:
- GCC (GNU Compiler Collection) – Mention that it’s one of the most popular compilers and works across various platforms (Windows, Mac, Linux).
- Clang – An alternative to GCC, often used on macOS and Linux.
- Steps:
Setting Up an IDE or Text Editor
Popular Choices:
- Visual Studio Code: Install VS Code and the C/C++ extension for syntax highlighting, intellisense, and debugging support.
- Code::Blocks: A simple, cross-platform IDE specifically for C/C++.
- Eclipse: Use CDT (C/C++ Development Tooling) plugin for Eclipse a full-featured IDE.
Configuring the Environment
After the finishing the compiler installation process it's time to configure the path,
configuring the environment path ensure the command like `gcc` , `clang` works properly from terminal
Setup Steps for windows :
- If you are install GCC properly from here . Next simply go to windows file explorer where the MinGW/GCC installed.
- Copy the MinGW path generally `C:\MinGW\bin`, then go to this PC option.
- Right click on it , click to properties and then go to advanced system settings.
- In bottom right part click to Environment, then under the System Variable
click to Path add Edit it - In the path Edit section click to new paste the path of MinGW path here.
Setup Steps for Macos :
- First, open your terminal and install GCC via Homebrew if don't have Homebrew download it fore here. and type `brew install gcc`
- After installation, locate the installation using `brew info gcc` command.
generally in mac the location would be (/opt/homebrew/Cellar/gcc) - Open the terminal and edit your shell configuration file. Depending on your
the file could be `.bash_profile`, .`zshrc`, or `.bashrc`. type nano ~/.zshrc. - Add the following line at the end of the file to include GCC in the PATH
export PATH="/usr/local/opt/gcc/bin:$PATH" , then Restart the terminal.
Run the Program
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
compile and run it using the command line (e.g., gcc hello.c -o hello && ./hello).