[Solved] Using external C/CPP libraries - Cross Compiling

I was able to figure it out, I was just inexperienced with CMake. This might sound basic to some of you but I’ll document what I did here if it could be of help for anyone in the future:

  1. Clone both Paho C and Paho C++ libs to different folders
  2. Open CMakeGui, select PahoC repo as the source, and create a folder called “bin_cross_compiled” inside it and use it as the target. Hit Configure → Specify Toolchain files for cross-compiling
  3. Use what is called a toolchain file, which basically contains CMAKE variables for cross-compiling, like which C compiler to use.

Mine is

➜ toolchains cat arm_legato_wp85xx.cmake
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

SET(CMAKE_C_COMPILER /opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)

  1. Make sure to change your CMAKE_INSTALL_PREFIX afterwards, otherwise make install will install the cross-compiled binaries to your host system.
  2. You can activate various settings (I used SSL, disabled testing, doc, etc…)
  3. Hit Generate
  4. Navigate to your build folder described in step 1
  5. run make then make install and you should have your binaries for Paho-C in the CMAKE_INSTALL_PREFIX folder.

The steps are pretty much the same for Paho C++ but you’ll need to also set up a variable to point to the build folder of PahoC since it needs it to build.

2 Likes