LEMON Tutorial  59
2 Compile Your First Code

First of all, you have to install LEMON on your system (see the Installation Guide for instructions). In this section, we assume that you use a Linux environment and GCC compiler.

Once you have installed the library, you may paste the following code segment into a file hello_lemon.cc to have a first working program that uses LEMON.

#include <iostream>
using namespace lemon;
using namespace std;
int main()
ListDigraph::Node u = g.addNode();
ListDigraph::Node v = g.addNode();
ListDigraph::Arc a = g.addArc(u, v);
cout << "Hello World! This is LEMON library here." << endl;
cout << "We have a directed graph with " << countNodes(g) << " nodes "
<< "and " << countArcs(g) << " arc." << endl;
return 0;

In this small example, a directed graph is created with two nodes and an arc added to it.

Now let us compile this code. (We suppose that you have it in a file called hello_lemon.cc.)

If LEMON is installed system-wide (into directory /usr/local), then it is very easy to compile this program with the following command (the argument -lemon tells the compiler that we are using the installed LEMON).

g++ -o hello_lemon hello_lemon.cc -lemon

As a result you will get the executable hello_lemon in the current directory, which you can run by the following command.


If LEMON is installed user-local into a directory (e.g. ~/lemon), then compiling the code is a bit more difficult. You have to issue a command like this.

g++ -o hello_lemon -I ~/lemon/include hello_lemon.cc -L ~/lemon/lib -lemon

If everything has gone well, then our program prints out the followings.

Hello World! This is LEMON library here.
We have a directed graph with 2 nodes and 1 arc.

If you managed to compile and run this example code without any problems, you may go on reading this tutorial to get to know the basic notions, features and tools of LEMON. However, if you encountered problems that you did not manage to solve, do not hesitate to contact us.

<< 1 Introduction | Home | 3 Basic Concepts >>