How to link an .so to a legato project

Hi, I have written a sepeate linux .so file that I would like to load/link to my legato application. How to I go about doing this?

I thought I would just need to add -l(path) for the file (using mkapp command line) , but that seems to just be ignored and I get file not found error.

Does one import linux shared library differently?

Thanks,
Karl

Have you seen the requires lib documentation? I think if you read that you will see how to use a shared library.

Hi, thanks for the reply. Yes I have had a look, but am still having the following problem.

in my CDEF I have

ldflags:
{
-l<libname>.so.1.0
}

In my ADEF I have

bundles:
{
file:
{
<library path>/<libname>.so.1.0 <libname>.so.1.0
}
}

And I can see it is copying the so into the path
<app path>/Target_Legato Debug/app/<app name>/staging/read-only/lib/

However when I build it I still get the error "Cannot find -l<lib name>.so.1.0

Any ideas?

Thanks,
Karl

Hi @karlkuhn

First of all, please make sure that your lib has been compiled with the toolchain used to build Legato apps.

Then, once you have your (ARM cross-compiled) .so file, you need two things:

  • tell the linker you need it
  • bundle it with your app

It looks like you managed to perform the second point, so let’s focus on the first one.

you can do it with ld flags, but actually it’s easier to do it with a libs section.
CDEF fragment:

requires: {
    lib: {
        /path/to/my/libfoo.so
    }
}

And that’s it. The build system will convert this to the correct command line for gcc/ld.
Obviously, you can use an environment variable to specify the path to the lib.

requires: {
    lib: {
        ${CURDIR}/libfoo.so  // NB: ${CURDIR} is current component root directory
    }
}

Hope this will help.

1 Like

Thanks for the reply @daav. I will give that a go and get back to you.

@daav I have tried to cross compile my library. It is a C++ library and builds fine using G++. However when I try to cross compile using

$WP85_TOOLCHAIN_DIR/arm-poky-linux-gnueabi-g++ -v -std=c++11 -o Platform.o Platform.cpp

I get fatal error: iostream: No such file or directory

which indicates something is up with g++ compiler or am I missing something silly?

with the build log

Using built-in specs.
COLLECT_GCC=/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++
COLLECT_LTO_WRAPPER=/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/lto-wrapper
Target: arm-poky-linux-gnueabi
Configured with: /work/build_src/tmp/work-shared/gcc-4.9.1-r0/gcc-4.9.1/configure --build=x86_64-linux --host=i686-pokysdk-linux --target=arm-poky-linux-gnueabi --prefix=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr --exec_prefix=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr --bindir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi --sbindir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi --libexecdir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi --datadir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/share --sysconfdir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/etc --sharedstatedir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/com --localstatedir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/var --libdir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi --includedir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/include --oldincludedir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/include --infodir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/share/info --mandir=/opt/swi/y17-ext/sysroots/i686-pokysdk-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/work/build_src/tmp/sysroots/i686-nativesdk-pokysdk-linux --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=arm-poky-linux-gnueabi- --without-local-prefix --enable-target-optspace --enable-lto --enable-libssp --disable-bootstrap --disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --with-gxx-include-dir=/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1 --with-build-time-tools=/work/build_src/tmp/sysroots/x86_64-linux/usr/arm-poky-linux-gnueabi/bin --with-sysroot=/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi --with-build-sysroot=/work/build_src/tmp/sysroots/swi-mdm9x15 --enable-poison-system-directories --with-mpfr=/work/build_src/tmp/sysroots/i686-nativesdk-pokysdk-linux --with-mpc=/work/build_src/tmp/sysroots/i686-nativesdk-pokysdk-linux --enable-nls --with-arch=armv7-a
Thread model: posix
gcc version 4.9.1 (GCC)
COLLECT_GCC_OPTIONS=‘-v’ ‘-std=c++11’ ‘-o’ ‘Platform.o’ ‘-shared-libgcc’ ‘-march=armv7-a’ ‘-mtls-dialect=gnu’
/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/cc1plus -quiet -v -iprefix /home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/ -D_GNU_SOURCE Platform.cpp -quiet -dumpbase Platform.cpp -march=armv7-a -mtls-dialect=gnu -auxbase Platform -std=c++11 -version -o /tmp/ccw7cgKn.s
GNU C++ (GCC) version 4.9.1 (arm-poky-linux-gnueabi)
compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127753
ignoring nonexistent directory “/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/…/…/…/…/…/arm-poky-linux-gnueabi/include”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1/arm-poky-linux-gnueabi”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.1/backward”
ignoring duplicate directory “/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/…/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/include”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/lib/gcc/arm-poky-linux-gnueabi/4.9.1/include”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/local/include”
ignoring duplicate directory “/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/…/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/include-fixed”
ignoring nonexistent directory “/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/…/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/…/…/…/…/…/arm-poky-linux-gnueabi/include”
ignoring nonexistent directory “/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/usr/include”
#include “…” search starts here:
#include <…> search starts here:
/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/include
/home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/…/…/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/include-fixed
End of search list.
GNU C++ (GCC) version 4.9.1 (arm-poky-linux-gnueabi)
compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127753
Compiler executable checksum: ed89415276d8770cbf2cccc7f69bfb90
In file included from Platform.cpp:1:0:
Platform.h:6:20: fatal error: iostream: No such file or directory
#include
^
compilation terminated.

Please verify your $LEGATO_SYSROOT env var is correctly set (should be something located in /home/user/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/xxx as well.

Then, all your gcc/g++ calls must be done with the –sysroot=$LEGATO_SYSROOT option.

Hi @daav , thanks that allowed me to cross compile the linux lib. I am now again having the original problem with linking that library.

I have tried your method above, I also tried the ldflags (in the cdef) option and finally I tried the ldflags option in the mkapp command line. But I still get the “cannot find library” issue. The .so is still be copied in correctly (the new one).

Below is my adef, cdef and build script along with the build log. (Sorry for the long post)

Component.cdef (229 Bytes)
DLC-Gateway-Legato.adef (390 Bytes)
Build Log.txt (23.5 KB)

Thanks again for your help

BUILD SCRIPT:

export PATH=PATH:~/legato/packages/legato.framework.16.10.3.wp85-wp750x-201705031608/resources/legato/bin:~/bin:~/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin;
export LEGATO_ROOT=~/legato/packages/legato.framework.16.10.3.wp85-wp750x-201705031608/resources/legato;
export LEGATO_SYSROOT=~/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/;
export LEGATO_SSROOT=~/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/armv7a-vfp-neon-poky-linux-gnueabi/;
export WP85_TOOLCHAIN_DIR=~/legato/packages/legato.toolchain.1.7.3.SWI9X15Y_07120900-wp85-wp750x-native-x86-201705021320/resources/native/sysroots/i686-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi;
export WP85_TOOLCHAIN_PREFIX=arm-poky-linux-gnueabi-;
export SOURCE_PATH=$1/$2;
export OBJECT_PATH=$1/obj/$3/$4;
export TARGET_PATH=$1/bin/$3/$4;
export TARGET_NAME=$5;
set -x;
$LEGATO_ROOT/bin/mkapp -v -t wp85 DLC-Gateway-Legato.adef;

Hi @karlkuhn

Just made the test.
Sounds like it comes from the “.1.0” extension suffix…
GCC (at least the version embedded in the Legato toolchain) apparently requires simple .so files (without extra extension) when working with -l option.
Could you give a try by renaming the .so.1.0 file to a simple .so?

Another possibility (if you don’t want to rename the file) would be to specify the full file name in an ldflags section, without any option, so than ld takes it directly as an input.

ldflags: {
    ${TARGET_PATH}/libDL4Api-Linux.so.1.0
}
1 Like

Excellent thanks @daav. That now builds without error.

One step forward :slight_smile:

So I upload that to the FX30, but get an error on the device when it tries to run it.

error loading shared lirbaries: libDL4Api-Linux.so: cannot open shared object file: No such file or directory.

Any ideas? Have I put it in the wrong location “/lib/”…

By looking at your ADEF, maybe you need to set the r permission?

bundles:
{
  file:
  {
    [rx] ${TARGET_PATH}/libDL4Api-Linux.so /lib/
  }
}
1 Like

Great that did! Thanks @daav.

1 Like