Elektra  0.8.26
Hello, Elektra

This basic tutorial shows you how to compile and run a very basic Elektra application. For this tutorial we assume that you installed Elektra and CMake on your machine. We also assume that you work a Unix based OS like Linux or macOS.

  1. Create a folder called Hello somewhere on your disk
  2. Copy the file examples/helloElektra.c to the folder Hello you just created
  3. Save a file with the following content
1 cmake_minimum_required(VERSION 3.0)
2 
3 find_package(Elektra REQUIRED)
4 
5 if (ELEKTRA_FOUND)
6  message (STATUS "Elektra ${ELEKTRA_VERSION} found")
7  include_directories (${ELEKTRA_INCLUDE_DIR})
8 
9  add_executable (hello helloElektra.c)
10  target_link_libraries (hello ${ELEKTRA_LIBRARIES})
11 else (ELEKTRA_FOUND)
12  message (FATAL_ERROR "Elektra not found")
13 endif (ELEKTRA_FOUND)

as CMakeLists.txt in the folder Hello.

  1. Open a shell and change into the directory Hello
  2. Create a build directory inside Hello, change into the build directory, and run Cmake:
1 mkdir build
2 cd build
3 cmake ..

. If everything worked until now, then CMake should print messages that look something like this:

1 -- The C compiler identification is AppleClang 8.1.0.8020042
2 -- The CXX compiler identification is AppleClang 8.1.0.8020042
3 -- Check for working C compiler: usr/bin/cc
4 -- Check for working C compiler: usr/bin/cc -- works
5 -- Detecting C compiler ABI info
6 -- Detecting C compiler ABI info - done
7 -- Detecting C compile features
8 -- Detecting C compile features - done
9 -- Check for working CXX compiler: usr/bin/c++
10 -- Check for working CXX compiler: usr/bin/c++ -- works
11 -- Detecting CXX compiler ABI info
12 -- Detecting CXX compiler ABI info - done
13 -- Detecting CXX compile features
14 -- Detecting CXX compile features - done
15 -- Elektra 0.8.19 found
16 -- Configuring done
17 -- Generating done
18 -- Build files have been written to: Hello/build
  1. No it’s time to build your application. For that step run make inside the folder Hello/build:
1 make

. If the last step completed successfully, then the build directory now contains the application hello.

  1. You can now run your Elektra application by calling ./hello inside the build directory. The output of the application should look something like this:
1 Open key database
2 Retrieve key set
3 Number of mappings: 0
4 Add new key system/test/hello
5 Number of mappings: 1
6 
7 hello, elektra
8 
9 Delete mappings
10 Close key database
  1. You can now change the content of helloElektra.c. If you want to compile and execute the updated code, then repeat steps 6 and 7.