cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Dependencies for and approach to cross-compiling the C SDK

JSondhof
7-Bedrock

Dependencies for and approach to cross-compiling the C SDK

For a lightweight data broker collecting field data and sending it into Thingworx I wish to use the C SDK. The underlying hardware runs a custom embedded linux and I have a cross-compiler on a host system with Ubuntu 14.04. I am developing my application in C++.

 

The optimal solution in my point of view would be that I can treat the SDK like a library: Compiling the bare SDK code into a shared library, include all necessary header files in my project and link against the .so. Am I missing something critical here? Is that even possible in the first place? I figured that the SDK has a dependency to an OpenSSL distribution at least, are there more external libraries to be regarded?

 

I have to admit that I haven't used CMake until now and struggle a little to understand how I can include the SDK into my Eclipse project using the simple GNU make builder. Also, it'd be awesome to have different build profiles (actually I have two right now, one that compiles a slimmed version to debug on the host system and another one for the target).

 

Any hint on how to accomplish the implementation on the custom linux target or general experiences with such setups is greatly appreciated!

ACCEPTED SOLUTION

Accepted Solutions

For those, interested in the matter: I figured it out myself. Now I can use the C SDK as standalone library, even integrated in C++.

 

The following needs to be done to crosscompile the SDK and to use it as library:

  1. Download and unpack the latest SDK bundle. The following is happening inside the resulting directory if not stated differently.
  2. Change the CMakeLists.txt file in the root directory to contain a platform specific section (for me it was "emlinux" for using a CC toolchain). I oriented myself on what was already there.
  3. Create a subfolder for the compiled target system files.
  4. Inside that folder, run 
    $ cmake .. -D <options of enabled SDK components> -DPLATFORM=emlinux -DCMAKE_INSTALL_PREFIX=/path/to/target/lib/folder/on/host
    $ make
    $ sudo make install
    The available options for compiling the SDK are documented in the Developer Guide.
  5. Go to the installation path and the includes/ directory containing all header files. As the installation with CMake for these headers does not include processing them (i.e. replacing compiler defines by the target specific values), some headers need to be adjusted. I did the following replacements according to the compiler defines set in the corresponding section for my specific build in the CMakeLists.txt file with CMake's add_definitions(...):
    • Set TW_TLS_INCLUDE to "twOpenSSL.h" in header twTLS.h.
    • Set TW_OS_INCLUDE to "twLinux-openssl.h" in header twOSPort.h.
    • Set OFFLINE_MSG_STORE  to 2 in headers twApi.h, twIos.h, twLinux.h, twLinux-openssl.h.
      There might be a better way to use CMake to automate these adjustments, but I haven't found any solution yet.
  6. If you want to use the C SDK out of C++ like I did, you have to change some variable names in the headers too, as they conflicted with the namespace C++ keyword: I changed it in the twMacros.h and twShapes.h files.
  7. Now you can include the library in you projects using the usual 
    -ltwCSdk -L/path/to/target/lib/folder/on/host
    compiler options.
  8. Before you can run your project on the target, you have to copy the twCSdk.so library file to the lib/ folder there.

If you want to compile for your host system, too, just the CMake usage differs, as the adjustments still need to be done.

 

View solution in original post

1 REPLY 1

For those, interested in the matter: I figured it out myself. Now I can use the C SDK as standalone library, even integrated in C++.

 

The following needs to be done to crosscompile the SDK and to use it as library:

  1. Download and unpack the latest SDK bundle. The following is happening inside the resulting directory if not stated differently.
  2. Change the CMakeLists.txt file in the root directory to contain a platform specific section (for me it was "emlinux" for using a CC toolchain). I oriented myself on what was already there.
  3. Create a subfolder for the compiled target system files.
  4. Inside that folder, run 
    $ cmake .. -D <options of enabled SDK components> -DPLATFORM=emlinux -DCMAKE_INSTALL_PREFIX=/path/to/target/lib/folder/on/host
    $ make
    $ sudo make install
    The available options for compiling the SDK are documented in the Developer Guide.
  5. Go to the installation path and the includes/ directory containing all header files. As the installation with CMake for these headers does not include processing them (i.e. replacing compiler defines by the target specific values), some headers need to be adjusted. I did the following replacements according to the compiler defines set in the corresponding section for my specific build in the CMakeLists.txt file with CMake's add_definitions(...):
    • Set TW_TLS_INCLUDE to "twOpenSSL.h" in header twTLS.h.
    • Set TW_OS_INCLUDE to "twLinux-openssl.h" in header twOSPort.h.
    • Set OFFLINE_MSG_STORE  to 2 in headers twApi.h, twIos.h, twLinux.h, twLinux-openssl.h.
      There might be a better way to use CMake to automate these adjustments, but I haven't found any solution yet.
  6. If you want to use the C SDK out of C++ like I did, you have to change some variable names in the headers too, as they conflicted with the namespace C++ keyword: I changed it in the twMacros.h and twShapes.h files.
  7. Now you can include the library in you projects using the usual 
    -ltwCSdk -L/path/to/target/lib/folder/on/host
    compiler options.
  8. Before you can run your project on the target, you have to copy the twCSdk.so library file to the lib/ folder there.

If you want to compile for your host system, too, just the CMake usage differs, as the adjustments still need to be done.

 

Announcements


Top Tags