Web Analytics Made Easy - Statcounter
Skip to content

Building on Linux#

This tutorial shows how to build a SAMSON Extension on Linux using Qt Creator.

Requirements#

If you have not installed the SAMSON SDK, please, follow the instructions from the Installation of SDK section.

  • Compiler gcc/g++ v.5.4+
  • CMake v.3.10+
  • Qt 6.8.2 (download Qt: https://www.qt.io/download)
  • Qt Creator (should be available when you install Qt) or another IDE you prefer. Qt Creator is necessary if you want to modify Qt forms.

Configuration of a project in Qt Creator#

Open the Qt Creator and click Open Project... or go to File > Open File or Project... (Ctrl+O). Choose the root CMakeLists.txt file in the folder with your SAMSON Extension(s) (Note: CMakeLists.txt from the parent folder to your SAMSON Extension, not the CMakeLists.txt that is inside of your SAMSON Extension folder).

Choose the root CMakeLists.txt

Configure Project#

  1. Choose the default kit (e.g., Desktop Qt 6.8.2 GCC 64 bit). If necessary, you can configure your kits in Manage Kits.

    Note

    If you have CMake, then the installed Qt Creator should generate a kit for it. Else, if Qt Creator did not detect CMake we refer to Qt tutorial on Setting Up CMake for setting up CMake in Qt Creator. Once CMake is installed, generating a project for your development environment is straightforward.

  2. Click on Details to unroll it.

  3. Choose only Debug and Release options and specify the paths for them as follows:

    • For Debug: PathToExtensions/build/Debug
    • For Release: PathToExtensions/build/Release
  4. Click Configure Project.

    Configure Project

You may see some errors in the Issues window. This is because it is necessary to specify some other CMake arguments for both Debug and Release builds. To do so, switch to the Projects mode (Ctrl+5) in the left sidebar.

Build Settings#

CMake configuration#

Now, you need to specify some build settings:

  1. Add a string variable called SAMSON_SDK_PATH and set it to the path to SAMSON SDK: $HOME/OneAngstrom/SAMSON-Sdks/8.0.0.

    Add string variable

  2. Add a boolean variable called DEBUG and toggle it to ON for the Debug build configuration and leave it OFF for the Release build configuration.

  3. Click Re-configure with Initial Parameters and press Yes in the pop-up dialog.

    CMake configuration

Now, the project should be ready for building. But to be able to use your SAMSON Extension, it should be installed in a specific SAMSON directory to make it available in your SAMSON installation.

Build Steps#

To ensure that your SAMSON Extension(s) is installed:

  1. Scroll down to Build Steps and click on Details to unroll the options.
  2. Check the install option.

Build steps: add the install option

Build#

On the left sidebar, click on Edit and you should see your project - you can expand it to see its content.

Let's now try to build the project. Click Ctrl+B to build the project or go to Build > Build Project "SAMSON-Elements".

You can see the build progress in the bottom right corner. The progress bar should go green if everything is alright. If it becomes red, then please check the Compile Output and also ensure that you properly specified the CMake variables mentioned above.

Note

Building the install target will automatically build your project.

Note

If your SAMSON Extension does not compile, you may have to install libstdc++ packages dev and static for the 64-bit architecture.

If the build was successful your SAMSON Extension should be available when you launch SAMSON. During startup, your SAMSON Extension will be loaded alongside with the SAMSON Extensions you added from SAMSON Connect, as well as other SAMSON Extensions you developed.

Run Settings#

SAMSON Extensions may be built in both Debug and Release configurations. SAMSON Extensions compiled in Release mode will be available only when launching the SAMSON-Core executable provided with SAMSON installation, while SAMSON Extensions compiled in Debug mode will be available only when launching the SAMSON-Core executable provided with SAMSON SDK installation which provides the Debug version of the SAMSON-Core executable. The Debug configuration is the one you should use to develop and debug your code, while the Release configuration is the one you should use when testing the performance of your SAMSON Extension, and when uploading it to SAMSON Connect. SAMSON Users only get the Release configuration, since this is the optimized one.

In order to let Qt Creator know which version of SAMSON to start, enter the path to the SAMSON-Core executable for each build configuration. For that switch to Projects mode (Ctrl+5) through the left sidebar and in the Run Settings create two run configurations (one for Release and one for Debug) and specify the following SAMSON-Core executables (not the SAMSON-Core.sh files):

  1. Set the executable in the Run configuration:

    $HOME/OneAngstrom/SAMSON-Sdks/8.0.0/SAMSON-Debug/Binaries/SAMSON-Core-Console

    $HOME/Applications/SAMSON.app/8.0.0/Binaries/SAMSON-Core-Console

    Important

    Replace $HOME with the path to your user folder.

    And save the run configuration as Debug or Release, respectively.

    Run configuration: set the SAMSON executable

  2. Add the following environment variables in the Environment section to let SAMSON search for frameworks or libraries to the correct location:

    LC_ALL=en_US.UTF-8
    LD_LIBRARY_PATH=$HOME/Qt/6.8.2/gcc_64/lib:$HOME/OneAngstrom/SAMSON-Sdks/8.0.0/SAMSON-Debug/Binaries
    
    LC_ALL=en_US.UTF-8
    LD_LIBRARY_PATH=$HOME/Qt/6.8.2/gcc_64/lib:$HOME/OneAngstrom/SAMSON/8.0.0/Binaries
    

    Important

    Replace $HOME with the path to your user folder.

    Run configuration: environment

Now when you build the install target (Ctrl+B) and run (Ctrl+R) SAMSON will be launched from Qt Creator.

Tip

If you choose Debug build and Debug run you can debug your SAMSON Extension, add breakpoints, and inspect variables values.

Run#

Now, you should be able to run SAMSON directly from Qt Creator and debug your SAMSON Extension(s), if necessary.

To run, click Ctrl+R or Build > Run.

If you have any issues or questions, please use the SAMSON Connect Forum or contact us.

Adding files to a SAMSON Extension#

You can add files to (or remove files from) your new SAMSON Extension (e.g. to add or remove classes, to wrap existing code, etc.). When you do so you need to regenerate the project. To do this you can run cmake again or let your IDE to run it. Another more simple way to do this without having to open a command window is to slightly alter the CMakeLists.txt file located in the SEMyElement (e.g. add or remove a whitespace somewhere) and save it: when building the project (see the next section), CMake will automatically detect the changes and will update the project.

Adding new SAMSON Extensions to the project#

When you generate a new SAMSON Extension with the SAMSON Extension Generator in the same folder with your other SAMSON Extensions, the Extension Generator will include the newly generated extensions into the root CMakeLists.txt via ADD_SUBDIRECTORY and this should be taken automatically into account next time you try to build the project.

Compatibility with older Linux distributions#

SAMSON supports Linux distributions with GLIBC 2.17 or higher. You can check the GLIBC version on your system via, for example, the following command in the terminal:

ldd --version

To make your SAMSON Extension able to run on older Linux distributions with GLIBC versions starting from 2.17 (released in December 2012), SAMSON SDK provides a header file (SBCSystemDefinitions.hpp) which defines GLIBC compatibility symbols that forces linking against symbols from a GLIBC version not higher than 2.17. This allows you to compile your SAMSON Extension on a recent Linux distribution while still supporting older distributions. This header is already included in some base classes so you do not need to include it - it will be included automatically. If you use an external library or external source code you might need to include this header in them:

#include "SBCSystemDefinitions.hpp"

It is necessary only if in your SAMSON Extension you are using GLIBC functionality which has been updated in recent versions (starting from the version 2.17), e.g. functions pow, exp, log for single precision floating-point numbers (float), and if you want to support older Linux distributions.

You can check which functionality from GLIBC your SAMSON Extension is using by executing the following command in the terminal against your SAMSON Extension library .so file:

objdump -T UUID.so | grep GLIBC

where UUID.so is the SAMSON Extension library. This will show you the list of GLIBC functions used in your SAMSON Extension and their version number.

When it is useful

Let's say that you build your SAMSON Extension on a recent Fedora or Ubuntu distribution which has GLIBC 2.27 or higher. If, for example, in your SAMSON Extension you are using pow, exp, or log functions for single precision floating-point numbers (float) (these functions were updated in GLIBC 2.27), then on older Linux distributions which have GLIBC older than 2.27 your SAMSON Extension will not be loaded in SAMSON because of the lack of GLIBC 2.27. The above-mentioned header allows to overcome this and support older GLIBC versions (starting from 2.17) even when building a SAMSON Extension using a newer GLIBC version.