This is a continuation to Setup C Tools tutorial I wrote in 2017 and Setup Java Tools in 2018. This one will show you briefly how to use Geany I.D.E. with GNU C++ Compiler. This includes an example so you will be able to try it and have it working first. Like the previous article, I dedicate this tutorial for purely beginners in both programming and in GNU/Linux. Note: screenshots below are taken from elementary OS 5.0 which is based on Ubuntu 18.04 (so, don't worry). Now, enjoy learning!



1. Install C++ Compiler


Just install GNU C++ Compiler:
$ sudo apt-get install g++

2. Install Geany


Like the previous article, I suggest you to use Geany Text Editor. It's a very lightweight replacement to DevC++ or Notepad++, or even Sublime Text: an all-language supporting programming IDE.
$ sudo apt-get install geany


3. Write Hello World


Here's a standard C++ source code you can copy and save as hello.cpp:

#include <iostream>using namespace std;int main (){cout << "Hello world!" << endl;return 0;}


4. Compile & Execute


Click Compile button then click Build and then Run. Or instead press F8, F9, F5 keys respectively. Voila, it shows a small terminal showing Hello World! message. It works!

(Back: Geany; front: result of the program showing on Terminal)


The Resulting Files


This little exercise creates three files: hello.cpp, hello.o, and hello (without extension). The source code, the object code, and the binary code files, respectively. The one you saw on Terminal above is hello, the executable program. You can run it manually by command line ./hello on your Terminal. You can learn more about these things better on C++ Book (Wikibooks).



Is Your Build Config Correct?


If you use Geany, once a C++ (.cpp) file saved, you can automatically compile it as Geany detects the compiler automatically. But in case you want to make sure, once you open a .cpp file, see Geany menu Settings > Set Build Config, it should looks like this.


  • Compile: g++ -Wall -c "%f"
  • Build: g++ -Wall -o "%e" "%f"


End Notes


For you who need a good source to learn basic C++, learn from cplusplus.com. For you who dream real C++ project(s), see KDE. I hope this simple tutorial really helps you a lot. Happy learning!


This article is licensed under CC BY-SA 3.0.


, , , , , , ,