How to cross compile libcurl with OpenWrt

Hello,

I'm quite new to C programming and cross compiling so I apologize in advance if I don't explain clear enough my problem but I'll try my best.I have a problem with cross compiling .c program with libcurl library. When I call it in terminal it looks liKe this:
/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc myProgram.c -o newFile

Result:

/tmp/ccdB6XHs.o: In function `main':
myProgram.c:(.text+0x3f8): undefined reference to `curl_global_init'
myProgram.c:(.text+0x400): undefined reference to `curl_easy_init'
myProgram.c:(.text+0x574): undefined reference to `curl_mime_init'
myProgram.c:(.text+0x584): undefined reference to `curl_mime_addpart'
myProgram.c:(.text+0x59c): undefined reference to `curl_mime_name'
myProgram.c:(.text+0x5b0): undefined reference to `curl_mime_filedata'
myProgram.c:(.text+0x5bc): undefined reference to `curl_mime_addpart'
myProgram.c:(.text+0x5d4): undefined reference to `curl_mime_name'
myProgram.c:(.text+0x5ec): undefined reference to `curl_mime_data'
myProgram.c:(.text+0x600): undefined reference to `curl_slist_append'
myProgram.c:(.text+0x628): undefined reference to `curl_easy_setopt'
myProgram.c:(.text+0x688): undefined reference to `curl_easy_setopt'
myProgram.c:(.text+0x6a8): undefined reference to `curl_easy_setopt'
myProgram.c:(.text+0x6b4): undefined reference to `curl_easy_perform'
myProgram.c:(.text+0x6dc): undefined reference to `curl_easy_strerror'
myProgram.c:(.text+0x700): undefined reference to `curl_easy_cleanup'
myProgram.c:(.text+0x70c): undefined reference to `curl_mime_free'
myProgram.c:(.text+0x718): undefined reference to `curl_slist_free_all'
collect2: error: ld returned 1 exit status

I have declared the staging dir and I have copied the files from my local lib and include directory, to the one that cross compiler uses but still it doesn't compile it. I've been stuck here for 2 days and can't really find of think of any solution so I would appreciate any help.

Thank you

libcurl is already included in Openwrt and the libraries get installed by its Makefile in the staging area. See package/network/utils/curl/Makefile

So, the libraries you need to link to are already available once you select the relevant curl package and library in menuconfig.

You're getting that error because you're not linking to libcurl. It needs to be specified on the command line with a -lcurl. And the linker needs to be able to find the libcurl.so in the staging_dir.

Usually this is best accomplished by creating an Openwrt package Makefile for your program. You're going to find it much easier to successfully compile your package if you create a proper package Makefile.

This should get you started: https://openwrt.org/docs/guide-developer/packages

There are many packages in the build tree, so have a look at a few for examples, particularly one of those that uses libcurl. You'll either need a directive TARGET_LDFLAGS += -lcurl in your Openwrt package Makefile, or link to it explicitly in the Makefile for your own program (just by adding a -lcurl to the compiler options).

Thank you.
I tried adding -lcurl to command line and apparently it tried to link to some directory but couldn't find the libs there. Here is result:
/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lcurl

I haven't made any makefiles or modified the existing ones, but I found libraries including libcurl.so, libcrypto.so and libssl.so and I copied them to folder
/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3

Then I tried to compile the program with -lcurl at the end of command and now the result looks like this:
/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3/libcurl.so: undefined reference to BIO_puts@OPENSSL_1_1_0' collect2: error: ld returned 1 exit status /staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/lib/gcc/mips-openwrt-linux-uclibc/4.8.3/libcurl.so: undefined reference to MD5_Update@OPENSSL_1_1_0'

and bunch of others as well but this @OPENSSL_1_1_0 is same for all.

You need to build your program using a package Makefile like I described above. Look at the link for instructions