Alexandre BM | 20 Jun 2012 17:49
Picon
Gravatar

gcc compile problem under ubuntu

Hello everybody,

I'm trying to compile a c programe that uses libcurl under Ubuntu 12.04,
Libcurl is correctly installed (I hope). but the linking is not working

gcc -lcurl functions.o main.o -o myprogram

I'm gettings these errors :

functions.c:(.text+0x5): undefined reference to `curl_easy_init'
functions.c:(.text+0x23): undefined reference to `curl_easy_setopt'
functions.c:(.text+0x2b): undefined reference to `curl_easy_perform'
functions.c:(.text+0x38): undefined reference to `curl_easy_cleanup'

Does anyone have an idea how can i fix it ?
Thanks ! :)

PS :

dpkg --list | grep curl

ii  curl                                   7.22.0-3ubuntu4
           Get a file from an HTTP, HTTPS or FTP server
ii  libcurl3                               7.22.0-3ubuntu4
           Multi-protocol file transfer library (OpenSSL)
ii  libcurl3-dbg                           7.22.0-3ubuntu4
           libcurl compiled with debug symbols
ii  libcurl3-gnutls                        7.22.0-3ubuntu4
           Multi-protocol file transfer library (GnuTLS)
ii  libcurl3-nss                           7.22.0-3ubuntu4
(Continue reading)

Ben Noordhuis | 20 Jun 2012 17:55
Picon

Re: gcc compile problem under ubuntu

On Wed, Jun 20, 2012 at 5:49 PM, Alexandre BM <salexandre.bm <at> gmail.com> wrote:
> Hello everybody,
>
> I'm trying to compile a c programe that uses libcurl under Ubuntu 12.04,
> Libcurl is correctly installed (I hope). but the linking is not working
>
> gcc -lcurl functions.o main.o -o myprogram
>
> I'm gettings these errors :
>
> functions.c:(.text+0x5): undefined reference to `curl_easy_init'
> functions.c:(.text+0x23): undefined reference to `curl_easy_setopt'
> functions.c:(.text+0x2b): undefined reference to `curl_easy_perform'
> functions.c:(.text+0x38): undefined reference to `curl_easy_cleanup'
>
> Does anyone have an idea how can i fix it ?

gcc on ubuntu 12.04 links with -Wl,--as-needed. You likely need to
pass -lcurl as the last argument, e.g.:

  $ gcc functions.o main.o -o myprogram -lcurl
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Alexandre BM | 20 Jun 2012 18:04
Picon
Gravatar

Re: gcc compile problem under ubuntu

On 20/06/2012 16:55, Ben Noordhuis wrote:
> On Wed, Jun 20, 2012 at 5:49 PM, Alexandre BM <salexandre.bm <at> gmail.com> wrote:
>> Hello everybody,
>>
>> I'm trying to compile a c programe that uses libcurl under Ubuntu 12.04,
>> Libcurl is correctly installed (I hope). but the linking is not working
>>
>> gcc -lcurl functions.o main.o -o myprogram
>>
>> I'm gettings these errors :
>>
>> functions.c:(.text+0x5): undefined reference to `curl_easy_init'
>> functions.c:(.text+0x23): undefined reference to `curl_easy_setopt'
>> functions.c:(.text+0x2b): undefined reference to `curl_easy_perform'
>> functions.c:(.text+0x38): undefined reference to `curl_easy_cleanup'
>>
>> Does anyone have an idea how can i fix it ?
> 
> gcc on ubuntu 12.04 links with -Wl,--as-needed. You likely need to
> pass -lcurl as the last argument, e.g.:
> 
>   $ gcc functions.o main.o -o myprogram -lcurl

So this is specific to ubuntu ? cause it's correctly working under
Debian ! can you explain me why ?

PS : thank's it's working now !

> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
(Continue reading)


Gmane