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

**URL:** <https://forum.legato.io/t/solved-using-external-c-cpp-libraries-cross-compiling/3090>\
**Category:** Uncategorized\
**Created:** [February 13, 2018, 11:56pm UTC](https://forum.legato.io/t/solved-using-external-c-cpp-libraries-cross-compiling/3090 "2018-02-13T23:56:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fjanicki](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/fjanicki/32/320_2.png) [@fjanicki](https://forum.legato.io/u/fjanicki)\
**Post date:** [February 13, 2018, 11:56pm UTC](https://forum.legato.io/t/solved-using-external-c-cpp-libraries-cross-compiling/3090/1 "2018-02-13T23:56:52Z")

</div>

I am trying to use an external library for a CPP project in Legato. I can create a C++ project and it compiles fine but I am not sure how to integrate and cross-compile an external library. I am able to use “headers only” libraries as they only contain templates but I am still unsure how to generate a .so to include it in the project.

I am trying to get up and running the PAHO project, more specifically the CPP version. The CPP version requires the C version to be installed first to compile. I can do it no problem on desktop but for sure the binaries won’t be working on legato.

They provide a CMakeList but I can’t find a way to use it with legato. Any help would really be appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![fjanicki](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/fjanicki/32/320_2.png) [@fjanicki](https://forum.legato.io/u/fjanicki)\
**Post date:** [February 14, 2018, 5:32pm UTC](https://forum.legato.io/t/solved-using-external-c-cpp-libraries-cross-compiling/3090/2 "2018-02-14T17:32:31Z")

</div>

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.
