# Problems with using libxml2

**URL:** <https://forum.legato.io/t/problems-with-using-libxml2/5521>\
**Category:** Uncategorized\
**Created:** [November 25, 2020, 12:42pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521 "2020-11-25T12:42:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 12:42pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/1 "2020-11-25T12:42:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 1:01pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/2 "2020-11-25T13:01:02Z")

</div>

do you find libxml2 in your module?

For example:  
find / -name “libxml2\*”

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 1:16pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/3 "2020-11-25T13:16:37Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/6/6115519d008313e2261814e2280c5bd3c16433c0.png)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 1:45pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/4 "2020-11-25T13:45:56Z")

</div>

can you attached your application here?

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

> **[Component Definition .cdef - Legato Docs](https://docs.legato.io/latest/defFilesCdef.html#defFilesCdef_requiresLib)**
>
> legato™ is an open source Linux-based embedded platform designed to simplify connected IoT application development

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 2:13pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/5 "2020-11-25T14:13:05Z")

</div>

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](https://docs.legato.io/latest/defFilesCdef.html)

// 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:  
{

}

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 2:14pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/6 "2020-11-25T14:14:07Z")

</div>

you need to zip the project

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 2:15pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/7 "2020-11-25T14:15:13Z")

</div>

And when i add xml2 in the requires: lib section It shows me this after running mkapp:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/5/51fb2e24be64c3662f870a9fca62b31c8ebbce01.png)

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 2:16pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/8 "2020-11-25T14:16:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 2:22pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/9 "2020-11-25T14:22:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 2:27pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/10 "2020-11-25T14:27:27Z")

</div>

Here is it on github:

> **[GitHub - NicolasHomolka/sierrawireless](https://github.com/NicolasHomolka/sierrawireless)**
>
> Contribute to NicolasHomolka/sierrawireless development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 3:36pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/11 "2020-11-25T15:36:58Z")

</div>

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
}

```

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 3:44pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/12 "2020-11-25T15:44:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 3:48pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/13 "2020-11-25T15:48:47Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 4:10pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/14 "2020-11-25T16:10:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 4:21pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/16 "2020-11-25T16:21:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 4:37pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/17 "2020-11-25T16:37:50Z")

</div>

![image](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/7/76a9d541247389db344a59512771103a26a97947.png)

---

<div class="post-metadata">

**Author:** ![Reinhard](https://avatars.discourse-cdn.com/v4/letter/r/a9adbd/32.png) [@Reinhard](https://forum.legato.io/u/Reinhard)\
**Post date:** [November 25, 2020, 4:39pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/18 "2020-11-25T16:39:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 25, 2020, 11:46pm UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/19 "2020-11-25T23:46:42Z")

</div>

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](https://forum.legato.io/uploads/short-url/vvgwxFIvIi3fpDXTEu1Fz1ZT3v4.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](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

```

---

<div class="post-metadata">

**Author:** ![reinhard2](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@reinhard2](https://forum.legato.io/u/reinhard2)\
**Post date:** [November 26, 2020, 7:18am UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/20 "2020-11-26T07:18:12Z")

</div>

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](http://xmlsoft.org/FAQ.html), 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.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [November 26, 2020, 7:30am UTC](https://forum.legato.io/t/problems-with-using-libxml2/5521/21 "2020-11-26T07:30:01Z")

</div>

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](http://source.sierrawireless.com)

[https://source.sierrawireless.com/resources/airprime/software/wp76xx/wp76xx-firmware-release-13,-d-,1-components/#sthash.2vlTNVx1.dpbs](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:

[Next page](https://forum.legato.io/t/problems-with-using-libxml2/5521.md?page=2)
