How to use libcurl from legato?

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 tocurl_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 tocurl_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 tocurl_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

Try adding

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.

It is also worth nothing that you should have:

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

instead of

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

Thank you. That was the piece I was missing.

Mark

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.

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

legato/apps/sample/httpGet

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.