1

I wrote a C library that utilizes the libcurl library to interact with a REST API. I wrote this on a debian based system, but am now attempting to use it on an Arduino, which runs an OpenWRT distribution. When trying to use it, I noticed there was an issue when the compiler attempts to use the libcurl library, so I wrote a super simple program to test it.

#include <curl/curl.h>

void main() {
    CURL *curl;
}

I then compiled it like so...

gcc -lcurl test.c -o test

and got back the following.

test.c: In function 'main':
test.c:4:2: error: unknown type name 'CURL'

libcurl was already installed on the device.

Package libcurl (7.29.0-1) installed in root is up to date.

Here's what displays when I run opkg files libcurl

Package libcurl (7.29.0-1) is installed on root and has the following files:
/usr/lib/libcurl.so.4
/usr/lib/libcurl.so.4.3.0

Having the hardest time trying to figure out what the problem is. This link was the only thing I found remotely close to being similar to my problem, but the solutions didn't work for me. Does anyone have any suggestions?

Thanks.

EDIT: So I think I found some more information about the problem. I think I'm missing a lot of the libcurl development packages as well because I looked at the opkg.conf file and saw that the only package list was the following.

http://downloads.arduino.cc/openwrtyun/1/packages

Maybe I need to find an OpenWRT package list having the extra libcurl packages I need? I can't seem to find them though.

Community
  • 1
  • 1
Garrett
  • 353
  • 7
  • 14
  • 3
    Do you have installed curl development package? – Absalón Valdés Jul 27 '15 at 03:44
  • It's possible I don't. This is pretty much the first time I used OpenWRT, so I'm unfamiliar with the opkg installer. I'm still looking to see on how I could check this, but do you happen to know it off the top of your head? – Garrett Jul 27 '15 at 03:50
  • the gcc linker handles/processes the command line parameters in the order given on the command line. that means the libraries need to be listed LAST. in the posted command line, there is no unresolved names to be resolved at the time the library reference is encountered – user3629249 Jul 27 '15 at 03:53
  • 1
    @user3629249 He's getting a compiler error, not a linker error – Dmitri Jul 27 '15 at 03:55
  • @user3629249 I also previously tried appending the libraries to the end of the compile command, but I still didn't have any luck. – Garrett Jul 27 '15 at 03:57
  • 3
    Strange error. It looks like you may have the curl dev package already. Otherwise it would complain that `curl.h` is missing. Suggestion: generate the preprocessor output with `gcc -E` and take a look at whether it really is using the correct `curl.h` or somehow getting a wrong one. There should be a typedef for the `CURL` type (`typedef void CURL` probably). – kaylum Jul 27 '15 at 04:50
  • See [What should `main()` return in C and C++?](http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c/18721336#18721336) too. When you're linking, put libraries (`-lcurl`) after source or object files (`test.c`) on the command line. Be cautious about using the name `test` for a program; the shell has a built-in command called `test` too. That can easily lead to confusion. – Jonathan Leffler Jul 27 '15 at 04:57
  • @AlanAu Thanks. This was helpful. I read the preprocessor output, and searched for the CURL typedef, and it was not found. So it seems that an incorrect header is being used for curl, but I guess where should I proceed from here? – Garrett Jul 27 '15 at 04:58
  • Look for `curl.h` in the PP output (mine is `/usr/include/curl/curl.h`). Which one is it using? Then open that file in the filesystem and see if that gives you any clues (e.g. does it look like it comes from the libcurl you installed). – kaylum Jul 27 '15 at 04:59
  • @AlanAu So my file is in the same exact place as yours, but seems very different from the header file located on the CURL Github. (https://github.com/bagder/curl/blob/master/include/curl/curl.h) Mine has a completely different author, and no CURL typedef. – Garrett Jul 27 '15 at 05:06
  • That ('no CURL typedef') is consistent with the error message. So, you'll need to work out whether you need to reinstall Curl or whether you need to be using Curl headers from a different location on your machine. – Jonathan Leffler Jul 27 '15 at 05:08
  • @AlanAu This is actually the file it is using (https://github.com/ap4y/Audio-Frameworks/blob/master/bin/cyberlink/headers/cybergarage/net/curi.h) Don't really know how that's possible? – Garrett Jul 27 '15 at 05:09
  • Did you somehow type "curi.h" instead of "curl.h"? (`i` instead of `l`.) –  Jul 27 '15 at 07:22

1 Answers1

1

So I was able to solve my problem, but I guess not "properly".

Apparently, the OpenWRT distribution I'm running uses a completely different libcurl library, and when I tried to uninstall it, the opkg package manager warned me that because it too also utilizes the currently installed libcurl library, it might break if I remove it.

Therefore, I manually installed the version of libcurl I needed from Github, and then made the proper references in my code to use this other version instead.

Thanks everyone for helping me get in the right direction.

Garrett
  • 353
  • 7
  • 14
  • It's probably as good a solution as any. Though you probably can make it cleaner by setting up your Makefile to find the right curl header/libraries and not actually make changes to your code (so the code continues to work for other systems). – kaylum Jul 27 '15 at 22:37