1.2. Creating statically linked binaries

When cross-compiling your CENA projects for another platform, it may be beneficial to use static linking instead of dynamic linking at runtime.

Warning

Not included in CENA

Static linking flags are purposefully not included in CENA. The method described here also impacts any parent project using CENA, which is not CENAs choice to make.

Please prefer including the changes below in you own projects CMakefile.

To build static libraries, add the following section to your projects toplevel CMakeLists.txt before any targets are created:

option(SEMODIA_CONTROLENGINE_ENABLE_STATIC_BUILD "Enable binaries to be statically linked" OFF)

Now you can check for the flag and add linker options for your target conditionally

if(SEMODIA_CONTROLENGINE_ENABLE_STATIC_BUILD)
    target_link_options(${CMakeTarget} PRIVATE -static -static-libgcc -static-libstdc++)
endif ()

Note that combining gtest - which needs threads - with static linking can be challenging. We would only recommend static linking for release binaries.