In order to work on C++, you need two software components i.e. a text utility to write your program and a compiler to compile and run your program. Often, these two components are clubbed together in a single application called Integrated Development environment or IDE. Text utility varies from operating system to operating and depends heavily on the programmer’s choice and comfort factor. Many people use Vi or Vim (Linux) to write code, old programmers prefers EMACS (Linux), while new breed of programmers move towards atom, notepad, nano, Eclipse etc. The files in which you write your code (set of instructions) in your editor are called source files and for C++ they typically are named with the extension .cpp, .cp, .h, or .c.
There are many C++ compilers available. Notable ones are given below:
- Apple C++. Xcode
- Bloodshed Dev-C++
- Clang C++
- Cygwin (GNU C++)
- Mentor Graphics
- MINGW - "Minimalist GNU for Windows"
- GNU CC source
- IBM C++
- Intel C++
- Microsoft Visual C++
- Oracle C++
- HP C++
The most used C/C++ compiler is GNU. We present the most common way to install a C++ compiler in each of Windows, Linux and Mac environment. In order to compile C++ code on Macbook, you need to install Xcode tool set which has got the Clang compiler for C/C++. It is an IDE (Integrated Development Environment) where you can write, compile, and run your programs. Post Xcode installation, you can use a text editor (atom, nano or vim) to write code and the Terminal to compile and run C++ programs. You can download Xcode from the App Store on your Mac. You can also simply install the xcode command line tools if you don't want the whole IDE. Another way to install C++ compiler is to use macOS package managers like MacPorts and Homebrew to install the needed compiler. You can instal gcc using brew install gcc. This command will GNU C++ compiler at its default location in /usr/local/Cellar/gcc/8.2.0/bin (assuming gcc version installed is 8.2.0).
To compile a source file say helloworld.cpp, you can write
XXX:~$ gcc helloworld.cpp.
The best way to run C++ programs on windows is to use an C/C++ compliant IDE. Dev-C++ from Bloodshed Software is the recommended IDE for C and C++ programming on Windows. Here are basic steps to install Dev C++ software on your windows machine.
1. Visit website for bloodshed (http://www.bloodshed.net) to download the Dev C++ on your Windows machine.
2. You can choose “Original Dev-C++ 5” Under package Dev-C++ 5.0 (4.9.9.2) with Mingw/GCC 3.4.2 compiler and GDB 5.2.1 debugger (9.0 MB).
3. Run the exe file that you have downloaded in step 2.
4. You will be directed to SourceForge website, and your C++ download will start automatically. Click on save button to save and once it is downloaded, click it to run.
5 Click Ok to few screens and complete installation
This concludes installation process and you can use Dev-C++ to compile your C or C++ programs.
You can install GCC compiler on Ubuntu (it comes as g++ for C++ and gcc for C programs) using the following command.
XXX:~$ sudo apt -get install g++
Then check the version using the following command
XXX:~$ g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0