# How to use libcurl from legato?

**URL:** <https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867>\
**Category:** Uncategorized\
**Created:** [November 8, 2018, 8:04pm UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867 "2018-11-08T20:04:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjbutsch](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mjbutsch](https://forum.legato.io/u/mjbutsch)\
**Post date:** [November 8, 2018, 8:04pm UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/1 "2018-11-08T20:04:21Z")

</div>

Hello,

I a have written a test app to POST data to my server from an FX30S.

It fails to build. Below is the output.

mark@ubuntu:~/workspace/aimInterface$ mkapp -t wp85 aimInterface.adef  
[1/1] Regenerating build script  
[6/8] Linking C executable  
FAILED: /opt/swi/y17-ext/sysroots/x86\_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/opt/swi/y17-ext/sysroots/armv7a-vfp-neon-poky-linux-gnueabi -o \_build\_aimInterface/wp85/app/aimInterface/staging/read-only/bin/aimInterface \_build\_aimInterface/wp85/app/aimInterface/obj/aimInterface/\_main.c.o -rdynamic -Wl,–enable-new-dtags,-rpath=“$ORIGIN/…/lib” -L\_build\_aimInterface/wp85/staging/read-only/lib “-L\_build\_aimInterface/wp85/staging/read-only/lib” -lComponent\_aimInterfaceComponent “-L\_build\_aimInterface/wp85/staging/read-only/lib” -lComponent\_aimInterfaceComponent “-L$LEGATO\_BUILD/framework/lib” -llegato -lpthread -lrt -ldl -lm  
\_build\_aimInterface/wp85/staging/read-only/lib/libComponent\_aimInterfaceComponent.so: undefined reference to `curl_easy_perform' _build_aimInterface/wp85/staging/read-only/lib/libComponent_aimInterfaceComponent.so: undefined reference to `curl\_easy\_init’  
\_build\_aimInterface/wp85/staging/read-only/lib/libComponent\_aimInterfaceComponent.so: undefined reference to `curl_easy_strerror' _build_aimInterface/wp85/staging/read-only/lib/libComponent_aimInterfaceComponent.so: undefined reference to `curl\_version’  
\_build\_aimInterface/wp85/staging/read-only/lib/libComponent\_aimInterfaceComponent.so: undefined reference to `curl_easy_setopt' _build_aimInterface/wp85/staging/read-only/lib/libComponent_aimInterfaceComponent.so: undefined reference to `curl\_easy\_cleanup’  
collect2: error: ld returned 1 exit status  
ninja: build stopped: subcommand failed.

I found some references that seemed to indicate that there needed to be a “file” section in the “requires:” section of the Component.cdef for the libraries:

```
file:
{
    /usr/lib/libcurl.so.5 /lib/
	/usr/lib/libgmp.so.10 /lib/
	/usr/lib/libgnutls.so.28	/lib/
	/usr/lib/libhogweed.so.2	/lib/
	/usr/lib/libnettle.so.4 /lib/
	/lib/libz.so.1 /lib/
}

```

but that didn’t help.

What piece of magic am I missing?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![shib](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shib](https://forum.legato.io/u/shib)\
**Post date:** [November 9, 2018, 1:50am UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/2 "2018-11-09T01:50:36Z")

</div>

Try adding

```auto
lib:
{
    curl
}  

```

to your .cdef, and then in your .c files make sure you #include \<curl/curl.h\>  
Let me know if you still have any trouble. It might be worth opening the httpget example app to compare.

---

<div class="post-metadata">

**Author:** ![shib](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shib](https://forum.legato.io/u/shib)\
**Post date:** [November 9, 2018, 2:35am UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/3 "2018-11-09T02:35:46Z")

</div>

It is also worth nothing that you should have:

```auto
file:
{
    /usr/lib/xxx /usr/lib/
}

```

instead of

```auto
file:
{
    /usr/lib/xxx /lib/
}

```

---

<div class="post-metadata">

**Author:** ![mjbutsch](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@mjbutsch](https://forum.legato.io/u/mjbutsch)\
**Post date:** [November 13, 2018, 5:26pm UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/4 "2018-11-13T17:26:34Z")

</div>

Thank you. That was the piece I was missing.

Mark

---

<div class="post-metadata">

**Author:** ![gvandewaetere](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/gvandewaetere/32/636_2.png) [@gvandewaetere](https://forum.legato.io/u/gvandewaetere)\
**Post date:** [March 12, 2019, 2:58pm UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/5 "2019-03-12T14:58:43Z")

</div>

Hello mjbutsch,

I am trying to do the same thing but so far without luck.  
Would you have some basic example code that I can look at?  
I am getting following error: mdcdatasession[31001]/mdcDataSessionComponent T=main | mdcDataSessionComponent.c GetUrl() 550 | curl\_easy\_perform() failed: Couldn’t connect to server

Kind regards,  
Giovanni.

---

<div class="post-metadata">

**Author:** ![shib](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shib](https://forum.legato.io/u/shib)\
**Post date:** [March 12, 2019, 9:28pm UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/6 "2019-03-12T21:28:00Z")

</div>

The http get example is a good place to start. It is a basic app that uses libcurl to perform an http get from [httpbin.org](http://httpbin.org)

legato/apps/sample/httpGet

---

<div class="post-metadata">

**Author:** ![gvandewaetere](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/gvandewaetere/32/636_2.png) [@gvandewaetere](https://forum.legato.io/u/gvandewaetere)\
**Post date:** [March 13, 2019, 12:03am UTC](https://forum.legato.io/t/how-to-use-libcurl-from-legato/3867/7 "2019-03-13T00:03:32Z")

</div>

Hello!

Thanks for the tip! I actually found out that the firewall was blocking curl since it was missing the established connection rule. Now I no longer have curl problems.

Kind regards,  
Giovanni.
