Problems with using libxml2

Hey,

I want to use libxml2 in my Legato Applications running on my WP85, but i am unable to get it working.

I am writing my Code in VSCode using a WSL for Ubuntu. I installed the libxml2 and libxml2-dev package on Ubuntu.

I am not sure how to properly Include the library in VSCode so that it recognizes the functions and headerfiles. I also tried different using different options in the .cdef/.adef files. Help would be really appreciated!

Thanks in Advance!

do you find libxml2 in your module?

For example:
find / -name “libxml2*”

On my WP? Yes it is

In the /usr/lib i am able to find libxml2.so.2.9.7

But after including the .h files and using the functions in my app .c file, i always get following error Message after running mkapp:

can you attached your application here?

BTW, here says you need to include xml stuff in cdef file

The Forum won’t let me Upload files so:

xmlTest.c :

// Include the core framework C APIs.
#include “legato.h”

// Include your component’s API interfaces.
#include “interfaces.h”
#include <libxml/parser.h>
#include <libxml/tree.h>

// This function is called only once on startup. Place your initialization and event registration
// here.
COMPONENT_INIT
{
xmlDocPtr doc;
doc = NULL;
if(doc == NULL)
{
LE_INFO(“Is Empty”);
}
doc = xmlParseFile(“test.xml”);
xmlFreeDoc(doc);
}

Component.cdef :

// This is component definition file that specifies the internal content and external interfaces
// of reusable software components.
//
// For more details on the component definition (.cdef) file format see:
// Component Definition .cdef - Legato Docs

// Source code files.
sources:
{
xmlTest.c
}

// Bind resources from the target module into your application.
requires:
{
// IPC APIs used by this component.
api:
{

}

// File paths local to your target module.
file:
{
    
}

// Directories on your target module to make accessible to the app.
dir:
{
   
}

// Linux filesystem device paths.

device:
{

}
component:
{
}

// Shared libraries pre-installed on the module.
lib:
{      
    xml2
}   

}

bundles:
{
file:
{
/home/reinhard/.leaf/wp85-toolchain_SWI9X15Y_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/lib/libxml2.so /lib/
}

}

cflags:
{
}

xmlTest.adef:

// Specify the bundled components for your application here. This section needs to contain a list
// of system paths to your component directory.

version: 1.0.0
maxFileSystemBytes: 512K
sandboxed: true
start: manual

components:
{
}

// Add the list of executables to be constructed and moved to the /bin directory of the app. The
// executable content is a list of the components inside the executable.
//
// Example binding format:
// clientExe.clientComponent.clientInterface → serverExe.serverComponent.serverInterface
executables:
{
xmlTest = ( xmlTestComponent )
}

// The processes section specifies processes to run when the app is started including environment
// variables, command-line arguments, limits, and fault handling actions.
processes:
{

run:
{
    ( xmlTest )
}

}

// Bindings that allow client side API interfaces to be bound to servers found within other
// applications in the system.
bindings:
{

}

you need to zip the project

And when i add xml2 in the requires: lib section It shows me this after running mkapp:
image

It tells me new Users can’t upload files, i created this acoount a few hours ago ^^

do you have google drive then?
you can put the link here.

Here is it on github:

I tried to compile for my WP76 module, and it works.
I just modify the component.cdef file to contain the following:

cflags:
{
	-I/opt/swi/SWI9X07Y_02.28.03.05/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2
}

What did you write in
requires:
{
lib:
}
}

And what does your mkapp command look like?
I if i just write xml under requires: lib: i still get undefined referene errors.
An if i write xml2 it tells me cannot find -lxml2

There is nothing in “requires” library section, I follow your code.
Are you sure your toolchain really containing these .h files?

#include <libxml/parser.h>
#include <libxml/tree.h>

BTW, I used Developer studio to compile:

23:34:47 **** Incremental Build of configuration Target_Legato_Debug for project xmlTest ****
make -C Target_Legato_Debug all 
make: Entering directory `/home/owner/legato/workspace/xmlTest/Target_Legato_Debug'
cd ..;mkapp -t wp76xx -o Target_Legato_Debug -w Target_Legato_Debug -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/atServices" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/airVantage/legacy" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/watchdog" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/portService" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/supervisor" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/logDaemon" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/positioning" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/secureStorage" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/wifi" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/modemServices" -i "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/interfaces/airVantage" -i /opt/swi/SWI9X07Y_02.28.03.05/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/ -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/dataConnectionService/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/test/watchdogChain" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/apps/platformServices/airVantageConnector" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/airVantage" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/modules/WiFi/apps/tools/wifi" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/positioning" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/secStore" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/uartMode/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/portService" -s "." -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/modemServices/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/audio/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/apps/tools" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/3rdParty" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/fwupdate/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/dataConnectionService" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/modules/WiFi/service" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/airVantage/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/fwupdate" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/positioning/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/devMode" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/secStore/platformAdaptor/default" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/apps/platformServices/mqttClient" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/atServices" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/modemServices" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components" -s "/home/owner/legato/packages/legato.framework.19.2.0.wp76xx-201906171244/resources/legato/components/uartMode" -C -g -X -g -L -g xmlTest.adef
[1/1] Regenerating build script
[1/9] Compiling C source
[2/9] Compiling C source
[3/9] Compiling C source
[4/9] Linking C library
[5/9] Bundling file
[6/9] Linking C executable
[7/9] Bundling file
[8/9] Creating info.properties
[9/9] Packaging app
make: Leaving directory `/home/owner/legato/workspace/xmlTest/Target_Legato_Debug'

23:34:48 Build Finished (took 584ms)

Im kind sure.

my mkapp command looks like this, maybe theres something wrong with it

mkapp -t wp85 xmlTest.adef -s /home/reinhard/myLeafWorkspace/CL_Agents/Components -i /home/reinhard/.leaf/wp85-toolchain_SWI9X15Y_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2

What do you have in

/home/reinhard/.leaf/wp85-toolchain_SWI9X15Y_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2

I also tried with
/home/reinhard/.leaf/wp85-toolchain_SWI9X15Y_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2/include

I am not 100% sure that i properly installed it

Oh and the 2 .h files definitely are under

/home/reinhard/.leaf/wp85-toolchain_SWI9X15Y_07.14.01.00-linux64/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2/include/libxml

Which is why i include them like <libxm/parser.h>

When running mkapp it seems to recognize the h files but cannot find the references to the functions in the h files hence the “undefined reference to xmlFreeDoc” error

This is my tree.h inside WP76 toolchain
/opt/swi/SWI9X07Y_02.28.03.05/sysroots/armv7a-neon-poky-linux-gnueabi/usr/include/libxml2/libxml

Do you find xmlFreeDoc in your side for the tree.h?
tree.h (38.5 KB)

I checked the toolchain SWI9X15Y_07140100-wp85-wp750x-native-x86_64-201907181020:

https://source.sierrawireless.com/resources/airprime/software/wpx5xx/wpx5xx-firmware-latest-release-components/#sthash.mohz30tW.dpbs

I don’t see anything related to libxml2

owner@CNHKG-EX-001367:~/legato/packages/legato.toolchain.2.2.3.SWI9X15Y_07140100-wp85-wp750x-native-x86_64-201907181020/resources/native/sysroots$ find ./ -name "*libxml*"
./armv7a-neon-poky-linux-gnueabi/usr/lib/libxml.so
./armv7a-neon-poky-linux-gnueabi/usr/lib/libxml.la
./armv7a-neon-poky-linux-gnueabi/usr/lib/libxml.so.0
./armv7a-neon-poky-linux-gnueabi/usr/lib/libxml.so.0.0.0
owner@CNHKG-EX-001367:~/legato/packages/legato.toolchain.2.2.3.SWI9X15Y_07140100-wp85-wp750x-native-x86_64-201907181020/resources/native/sysroots$ find ./ -name "tree.h"./armv7a-neon-poky-linux-gnueabi/usr/src/kernel/kernel/rcu/tree.h
./armv7a-neon-poky-linux-gnueabi/usr/src/kernel/include/config/quota/tree.h
./x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/6.2.0/plugin/include/tree.h
owner@CNHKG-EX-001367:~/legato/packages/legato.toolchain.2.2.3.SWI9X15Y_07140100-wp85-wp750x-native-x86_64-2019

I had to make a second account because the forum wouldn’ let me post for another 6 hours cause it’s a new account.

I do find xmlFreeDoc in my tree.h yes.

I tried to add libxml2 to my toolchain, i basically just installed it in the include directory like in " I want to install my own copy of libxml2 in my home directory and link my programs against it, but it doesn’t work" explained in FAQ · Wiki · GNOME / libxml2 · GitLab, and hoped it would work.

Is there a way to proper way to add libxml2 to the toolchain? And if there is can you show me?

Thanks for your help btw, i am new to this kind of stuff and still a bit lost with things like these.

I suspect the libxml2 you add to the toolchain is not an official one.
The official way should be using the libxml2 stuff from yocto recipe.

Here is what I try on WP76 source:

  1. download the yocto source from source.sierrawireless.com

https://source.sierrawireless.com/resources/airprime/software/wp76xx/wp76xx-firmware-release-13,-d-,1-components/#sthash.2vlTNVx1.dpbs

  1. go to ./meta-swi/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc

3.add the following line:
IMAGE_INSTALL_append = " libxml2"

  1. Make the yocto image

  2. the include path now should be in yocto/build_bin/tmp/work/armv7a-neon-poky-linux-gnueabi/libxml2/2.9.7-r0/image/usr/include/libxml2/

  3. in component.cdef, add the following:

    cflags:
    {

     -I/home/owner/Yocto/WP76/R13.3/yocto/build_bin/tmp/work/armv7a-neon-poky-linux-gnueabi/libxml2/2.9.7-r0/image/usr/include/libxml2/
    

    }