Issue while linking jansson shared library


#1

Hi, I am trying a sample application for connecting mangOH Green to Google Cloud.
After spending some time for porting the example as per updated libraries on which the application depends, I am facing an issue with linking a shared library called libjansson.

I referred the documentation and procedure to compile and install the Jansson library from the Getting Started page on their website.

In my Component.cdef, I have:

ldflags:
{
    -ljansson -ljwt -lcrypto -L/usr/local/lib
}

Problem statement:
When I build the code, I get following error.

/usr/local/lib/libjansson.so: file not recognized: File format not recognized

My interpretation of the issue is, is the problem with not cross-compiling libjansson? I have compiled Jansson straight and simple, do I have to build it with any considerations for legato?
The documentation for Jansson has a CMake section, which says,

By default the CMake project will generate build files for building the static library. To build the shared version use: cmake -DJANSSON_BUILD_SHARED_LIBS=1

I have done this step.
Is there anything else specific to legato?

What I have tried:
To know if the Jansson is properly installed or not, I wrote a simple ‘Hello World’ program in C and it had a

#include <jansson.h>

and was build using

gcc -o HelloWorld hello.c -ljansson

And, it did not report any linker errors related to Jansson (or libjansson.so)

Additional details if required:

Existing system:

  1. I have installed legato17-08.1 on my host (linux - ubuntu16.04 LTS) computer, used a zip, did not clone.

  2. I have installed latest toolchain (Release 14) from sierra wireless.

  3. I have installed legato application developer studio version 5.2.

  4. I have a mangOH Green board with me, it has a WP8548 chip on it and I have tested it with helloWorld program that I built and deployed on the device using legato application developer studio version 5.2.

  5. I am aware of the process of running ‘bin/legs’ every time I open a terminal for supporting commands related to legato.

  6. I have been able to build (on command line) sample applications provided by legato.


#2

It looks like the build system is picking up some lib from your system.

How are you building Legato? make wp85?

What about your app?


#3

@CoRfr: Thanks for responding.

I am absolutely sure that the application I am trying to build uses Jansson library by means of a .so file, libjansson.so. To support this, I have already compiled and installed the Jansson library and I can see the files that have been put under /usr/local/lib/ directory.

Its just that I am unable to understand why the linker is unable to understand the file format, while gcc does seem to have no issues.

To answer your question regarding how I build legato, Yes I used wp85 to build legato, The application I am trying to work with, is being built with make wp85.


#4

Cross-compiled libraries should be in a path such as /usr/local/ on your host, since this is really meant for files with the same architecture as your host (x86-64 for instance).

Instead you should rely on something like externalBuild to provide a Component.cdef that just ‘represents’ jansson from a Legato point of view.

That way Legato knows how to compile it and can take care of cross-compiling it for you.

Jansson is a bit of a particular case since the source code is already in Legato, and it is build as a dependency to some framework tools, so you can do something like -L${LEGATO_BUILD}/framework/libjansson/lib/ -ljansson for ldflags and -I${LEGATO_BUILD}/framework/libjansson/include for cflags.


#5

Thanks. With your inputs, I have managed to resolve the issues related to libjansson.so.

Another question: Can an external library cross-compile another external library using externalBuild? And, eventually both of them will be used in my application. In short, can a Component.cdef, (placed in the directory which contains the source for an external library) having an externalBuild section, also contain a required section with component?


#6

Glad you were able to solve your build issue.

As for your question, I think that yes externalBuild and required: components: are not mutually exclusive, so it should work.