Including kodo-cpp in Your Application¶
This guide shows how to include the kodo-cpp library in your application.
First of all, you need to build kodo-cpp following the Getting Started guide. If you want to cross-compile for your target platform (e.g. Android, iOS, Raspberry Pi), please follow the Cross-compilation and Tool Options section.
In principle, you can use the library with any build system. Basically, you can choose between the shared library and the static library.
After building kodo-cpp, you can install the static libraries to your target
folder with the following command (the
install_path option specifies
the target folder which will be
static_test in this example):
python waf install --install_static_libs --install_path="./static_test"
Actually, kodo-cpp is a header-only wrapper for the kodo-c static library that
libkodoc_static.a on Linux and Mac and
Windows. The install command also installs the static libraries from the
kodo-cpp dependencies (you will need the
as well to link your application).
You can link with these static libraries using your own build system. Of course,
you will need to include
kodocpp.hpp in your code that depends on other
header files. All the necessary header files are installed to the
folder within the specified
Now we copy an existing kodo-cpp example (sparse_seed) to the
static_test folder and we compile it to a binary called
cp examples/sparse_seed/sparse_seed.cpp static_test/myapp.cpp cd static_test
The following command demonstrates the necessary flags for the g++ compiler (other compilers require similar settings):
g++ myapp.cpp -o myapp -std=c++11 -I./include -Wl,-Bstatic -L. \ -lkodoc_static -lfifi -lcpuid -Wl,-Bdynamic
In practice, you should set the
-L flags to the path where you
installed the static libraries.
Now you should be able to run the new binary (note that this binary will be quite large, since it includes all the static libraries):
To reduce the size of the resulting binary, you can add the
-s flag to the
g++ command above to strip all debugging symbols.