Building a SAMSON Element on Linux

Facebooktwittergoogle_plusredditpinterestlinkedinmailFacebooktwittergoogle_plusredditpinterestlinkedinmail

This tutorial shows how to build SAMSON Elements on Linux using QtCreator. For other IDE, please, check the Main steps to configure a project for your SAMSON Element.
This tutorial was done with QtCreator v.4.4.1 and Qt 5.9.3. For an older version, please, check SAMSON School 2017: Introduction and installation of the SAMSON SDK.

If you experience any problems with building your SAMSON Element, please let us know on SAMSON-Connect forum.

Content

  1. Requirements
  2. Main steps to configure a project
  3. Configuration of a project in QtCreator
  4. Adding files to your SAMSON Element
  5. Building step
  6. Running SAMSON from QtCreator

Requirements

If you have not installed SAMSON SDK, please, follow instructions from Installing the SAMSON SDK.

  • Compiler gcc/g++ v.5.4+
  • CMake v.2.8.9+
  • Qt5.9.3
  • QtCreator (should be available when you install Qt) or another IDE you prefer. QtCreator is necessary if you want to modify Qt forms.

Main steps to configure a project for your SAMSON Element

Here we list the main steps for configuration of a SAMSON Element project. Application of these steps in QtCreator is described in the sections below.

Assume that Qt is installed in YourQtPath (i.e. the folder which contains the Qt5.9.3 folder), SAMSON is installed in YourSAMSONPath/SAMSON/0.7.0 (i.e. the folder which contains the Binaries folder), and the SAMSON SDK is installed in YourSDKPath/SDK/0.7.0/ (i.e. the folder which contains the following sub-folders: cmake, include, libs, SAMSON-Debug).

  1. You can configure a project by going to the folder where your SAMSON Element is stored, opening the build folder (if there is no such folder, create it) and executing the following command in terminal (see CMake help: “cmake -h”):
    cmake -DSAMSON_SDK_PATH=YourSDKPath/SDK/0.7.0 -G"CodeLite - Unix Makefiles" -DQT5_CMAKE_INCLUDE_DIR=YourQtPath/Qt5.9.3/5.9.3/gcc_64/lib/cmake/ ..
    Or you can open a project in the IDE of your choice and choose the root CMakeList.txt of your newly generated element (CMakeList.txt from the parent folder to your SAMSON Element, not CMakeList.txt inside the SAMSON Element folder) Configure Release and Debug builds by provoding the following variables:

    • Provide a string variable named SAMSON_SDK_PATH and set its value to the SAMSON SDK path: YourSDKPath/SDK/0.7.0/
    • Provide a boolean variable named DEBUG and set its value to TRUE (ON) for the Debug build and to FALSE (OFF) for the Release build. If not present, provide a string variable named CMAKE_BUILD_TYPE and set its value to Debug for the Debug build or to Release for the Release build.
    • [Optional] If Qt 5.9.3 was not identified by the IDE you use, you will need to specify a path to the Qt cmake folder. For that, add a string variable named QT5_CMAKE_INCLUDE_DIR and set its value to the Qt cmake path: YourQtPath/Qt5.9.3/5.9.3/gcc_64/lib/cmake”
  2. For both Release and Debug builds, set the install target so that after a successful compilation your SAMSON Element would be installed in a special SAMSON directory to make it available in your SAMSON installation.
  3. To be able to run SAMSON from QtCreator, specify the following SAMSON-Core executables (not SAMSON-Core.sh files) in run configurations:
    • for Debug run configuration: YourSDKPath/SDK/0.7.0/SAMSON-Debug/Binaries/SAMSON-Core
    • for Release run configuration: YourSAMSONPath/SAMSON/0.7.0/Binaries/SAMSON-Core

    Note that a SAMSON Element compiled in Release mode will be available only when launching the SAMSON-Core executable provided with SAMSON installation, while a SAMSON Element compiled in Debug mode will be available only when launching the SAMSON-Core executable provided with SAMSON SDK installation.

  4. You will need to specify some environment variables to let SAMSON search for frameworks or libraries to the correct location. For that, for each run configuration (Release and Debug) in Run Environment add a variable named LD_LIBRARY_PATH and fill it with the following absolute paths (see image below):
    • for Debug run configuration: paths corresponding to the location of Qt framework and SAMSON debug libraries:
      YourQtPath/Qt5.9.3/5.9.3/gcc_64/lib:YourSDKPath/SDK/0.7.0/SAMSON-Debug/Binaries
    • for Release run configuration:
      YourSAMSONPath/SAMSON/0.7.0/Binaries/SAMSONQtLibs/:YourSAMSONPath/SAMSON/0.7.0/Binaries/

    Also, for both Release and Debug run configurations, add a variable named LC_ALL and set its value to en_US.UTF-8

Configuration of a project in QtCreator

If you have CMake installed QtCreator should generate a kit for it. Else, if QtCreator did not detect CMake we refer to Qt tutorial on Setting Up CMake for setting up CMake in QtCreator.

Once CMake is installed, generating a project for your development environment is straightforward.

Assume that Qt is installed in YourQtPath (i.e. the folder which contains the Qt5.9.3 folder), SAMSON is installed in YourSAMSONPath/SAMSON/0.7.0 (i.e. the folder which contains the Binaries folder), and the SAMSON SDK is installed in YourSDKPath/SDK/0.7.0/ (i.e. the folder which contains the following sub-folders: cmake, include, libs, SAMSON-Debug).

Open QtCreator and click on Open Project.

Click Open Project

Choose the root CMakeList.txt of your newly generated element (CMakeList.txt from the parent folder to your SAMSON Element, not CMakeList.txt inside the SAMSON Element folder).

Choose CMakeList.txt

Choose the Build&Run kit (if necessary, you can configure your kits in Options → Build&Run → Kits), set build folders for Debug and Release, and press the Configure Project button.

Set paths for Debug and Release builds

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

  • Add a string variable named SAMSON_SDK_PATH and set its value to the SAMSON SDK path: SDK_PATH/0.7.0/
  • Provide a boolean variable named DEBUG and set its value to TRUE (ON) for the Debug build and to FALSE (OFF) for the Release build. Check a string variable named CMAKE_BUILD_TYPE: set its value to Debug for the Debug build or to Release for the Release build
  • [Optional] QtCreator should have determined Qt5.9.3 you installed. If not, you will need to specify a path to Qt cmake folder. For that, add a string variable named QT5_CMAKE_INCLUDE_DIR and set its value to the Qt cmake path: YourQtPath/Qt5.9.3/5.9.3/gcc_64/lib/cmake”

Specify CMake variables for both Debug and Release builds

Once you specified the variables for the build, press Apply Configuration Changes and you should see a set of settings variables defined by cmake like on the image below.

This generates a project for your development environment. In the Edit mode (Ctrl+2) you should see a structure like on the image below:

Adding files to your SAMSON Element

You may need to add files to (or remove files from) your new SAMSON Element (e.g. to add or remove classes, to wrap existing code, etc.). When you do so, you should run cmake again to regenerate a project for your development environment. One 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 a whitespace somewhere) and save it: when building the project (see the next section), CMake will detect the changes and update the project.

Building step

Once your project is created, you can now browse your SAMSON Element files and edit your code. The project contains one target for your SAMSON Element (SEMyElement), as well as some cmake-specific targets. When you generate new SAMSON Elements with the Element Generator in the same folder, cmake will re-generate the project files and will add new targets as needed.

You may now check that your code compiles by either building the target corresponding to it (e.g. SEMyElement) or if your solution contains several SAMSON Elements and you want to compile them all at once, by building the build all target.

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

Note that SAMSON Elements may be built in both Debug and Release configurations. 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 Element, and when uploading it to SAMSON Connect.

To be able to use your SAMSON Element, it should be installed in a specific SAMSON directory to make it available in your SAMSON installation.

For making it possible, switch to Projects mode (Ctrl+5) and in the Build Settings for each build configuration (Release and Debug) set in Build Steps target to install as it is shown in the image below.

Set install build

Now you can build the install target (either in Release or Debug configurations) to install your new SAMSON Element (building the install target will automatically build your project). If the build was successful your SAMSON Element should be available when you launch SAMSON (for Release configuration – SAMSON-Core from SAMSON installation, for Debug configuration – SAMSON-Core from the SAMSON SDK installation). During startup, your SAMSON Element will be loaded alongside with the SAMSON Elements you added from SAMSON Connect, as well as other SAMSON Elements you developed.

Running SAMSON from QtCreator

Note that a SAMSON Element compiled in Release mode will be available only when launching the SAMSON-Core executable provided with SAMSON installation, while a SAMSON Element compiled in Debug mode will be available only when launching the SAMSON-Core executable provided with SAMSON SDK installation. SAMSON Users only get the Release configuration, since this is the optimized one. The SAMSON SDK installer, though, adds a Debug version of the SAMSON-Core executable. It is this version that should be started when testing or debugging SAMSON Elements compiled in the Debug configuration.

In order to let QtCreator 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) and in the Run Settings create two run configurations (one for Release and one for Debug) and specify the following SAMSON-Core executables (not SAMSON-Core.sh files):

  • for Debug run configuration: YourSDKPath/SDK/0.7.0/SAMSON-Debug/Binaries/SAMSON-Core
  • for Release run configuration: YourSAMSONPath/SAMSON/0.7.0/Binaries/SAMSON-Core

You may also add some command line arguments, like: –logconsole –disablenetwork –import –logfile “file” –logdefaultfile.

Set the SAMSON-Core executable

We need to setup some environment variables to let SAMSON search for frameworks or libraries to the correct location. For each run configuration (Release and Debug) in Run Environment add a variable named LD_LIBRARY_PATH and fill it with the following absolute paths (see image below):

  • for Debug run configuration: paths corresponding to the location of Qt framework and SAMSON debug libraries:
    YourQtPath/Qt5.9.3/5.9.3/gcc_64/lib:YourSDKPath/SDK/0.7.0/SAMSON-Debug/Binaries
  • for Release run configuration:
    YourSAMSONPath/SAMSON/0.7.0/Binaries/SAMSONQtLibs/:YourSAMSONPath/SAMSON/0.7.0/Binaries/

Also, for both Release and Debug run configurations, add a variable named LC_ALL and set its value to en_US.UTF-8

Set environment variables for both Debug and Release run configurations

Now when you build the install target (Ctrl+B) and run (Ctrl+R) SAMSON will launch from QtCreator.

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

Facebooktwittergoogle_plusredditpinterestlinkedinmailFacebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *