Search code examples
gcccross-compilingopenwrttoolchain

libcurl issue when cross compiling C on MAC


I was cross compiling C with toolchain from OpenWRT on MAC OS. The C program has a dependancy on libcurl which I already installed. However, when i build the C program, i got the error messages as below.

1.Installed libcurl on MAC

brew install curl 

2.Used toolbarchain to cross compile the main.c

toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc -I/usr/local/opt/curl/include main.c

3.Compilation errors

In file included from /usr/local/opt/curl/include/curl/curl.h:35:0,
             from main.c:4:
/usr/local/opt/curl/include/curl/curlrules.h:142:3: error: size of array '__curl_rule_01__' is negative
__curl_rule_01__
^
/usr/local/opt/curl/include/curl/curlrules.h:152:3: error: size of array '__curl_rule_02__' is negative

curl_rule_02


Solution

  • You will need to cross compile curl/libcurl using your mips toolchain. ( In fact you should do this for all other dependencies )

    You have installed curl using brew, which essentially put x64 version of curl on your system.

    There are certain headers in curl which gets generated at compile time ( I think curlbuild.h ) These headers define macros based on the architecture e.g. CURL_SIZEOF_LONG

    As you are using curl headers (which were prepared for x64 arch ) to build mips application, it is unable to find the correct CURL_SIZEOF_LONG macro, leading -1 as a value.

    Besides, at some point you will need to link against libcurl library. your current library will never link if you are using mips toolchain. So try cross-compiling curl first and use that version.