Find the answer to your Linux question:
Results 1 to 10 of 10
I am attempting to build a program that utilizes libcurl - the library is physically located in /usr/lib as libcurl.so.4.0.1 there is also a link that points to it from ...
  1. #1
    Just Joined!
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    6

    gcc not finding library

    I am attempting to build a program that utilizes libcurl - the library is physically located in /usr/lib as libcurl.so.4.0.1 there is also a link that points to it from libcurl.so, also located in /usr/lib
    code is as follows
    #include <stdio.h>
    #include <curl/curl.h>

    int main(void)
    {
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "www.google.com");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    }
    return 0;
    }

    compiler invoked
    gcc -o simple.c simple.o -l/usr/lib/libcurl.so.4.0.1
    error below
    /usr/bin/ld: cannot find -l/usr/lib/libcurl.so.4.0.1
    collect2: ld returned 1 exit status

    I have also tried to use -llibcurl, -l/usr/lib/libcurl.so, always same result,
    what am I missing??

    any assistance appreciated
    thanks

    tom

  2. #2
    Trusted Penguin Dapper Dan's Avatar
    Join Date
    Oct 2004
    Location
    The Sovereign State of South Carolina
    Posts
    4,562
    If I am reading your post correctly, you are saying that libcurl.so.4.0.1 IS in /usr/lib? If that is the case, I'm not sure why it is not being detected. In the distros on this box I'm at, (Ubuntu Gusty, Slackware 12 and Crux 2.3), all only have version 4.0.0 of libcurl. If on the other hand, I'm reading your post wrong, and you don't know what version you actually have, it might be you have 4.0.0 or an earlier version like me and need to install libcurl 4.01. What versions are showing in /usr/lib?
    Code:
    ls -l /usr/lib/libcurl*
    Linux Mint + IceWM Registered:#371367 New Members: click here

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    6
    I am running FC8 and libcurl is in fact located in /usr/lib -
    ls -l libcurl* yields the following
    lrwxrwxrwx 1 root root 16 2007-11-24 11:59 libcurl.so -> libcurl.so.4.0.1
    lrwxrwxrwx 1 root root 16 2007-11-24 11:56 libcurl.so.4 -> libcurl.so.4.0.1
    -rwxr-xr-x 1 root root 243320 2007-11-18 12:07 libcurl.so.4.0.1

    gcc should be finding it but it is not and that is what I don't understand

  4. #4
    Trusted Penguin Dapper Dan's Avatar
    Join Date
    Oct 2004
    Location
    The Sovereign State of South Carolina
    Posts
    4,562
    I'll tell you outright, I've never built a program, but I've compiled many. I Googled
    -l/usr/lib/libcurl and I come up with absolutely nothing. Now I may be completely off base here, but what sticks out to me is the -l in -l/usr/lib/libcurl.so.4.0.1. Is this something the compiler returned? Seems to me the "-l" should be a compiler option. As it is, there is no space between -l and /usr/lib/libcurl*. Could it be that it is not being found because it's looking for a directory first called -l? When it should somehow be:
    Code:
    gcc -o simple.c simple.o -l /usr/lib/libcurl.so.4.0.1
    I have no way to know... Just thought I'd throw out my thoughts about it just in case there could possibly be something to it. I'm sorry I couldn't help more...

    EDIT: Did some more Googleing and the -l does appear right up against the directories, though the ones I've seen are capitol "L" as in -L/usr/lib/libcurl.so.4.0.1. Good examples on this page.
    Last edited by Dapper Dan; 12-02-2007 at 04:38 PM.
    Linux Mint + IceWM Registered:#371367 New Members: click here

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    6
    the -l switch is for the linker and what follows is the library name - it makes no difference if there is a space between the library name and -l

  6. #6
    drl
    drl is online now
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    I don't do much compiling either, so I need a mental map of what goes where.

    I place compiler source input files at the end of the command, the standard location as with most *nix commands. Your statement says that you wish to write the linked binary on file simple.c, probably not what you want:
    Quote Originally Posted by nga_tom
    gcc -o simple.c simple.o -l/usr/lib/libcurl.so.4.0.1
    The gcc command is non-trivial, but there is a general order to be followed.

    I suggest you 1) make sure you have a copy of your c input file, 2) look at man gcc, which includes:
    -llibrary
    -l library
    Search the library named library when linking. (The second alter-
    native with the library as a separate argument is only for POSIX
    compliance and is not recommended.)

    It makes a difference where in the command you write this option;
    the linker searches and processes libraries and object files in the
    order they are specified. Thus, foo.o -lz bar.o searches library z
    after file foo.o but before bar.o. If bar.o refers to functions in
    z, those functions may not be loaded.
    There still may be a problem locating the library, but correct the command first, and let us see where that leaves us.
    Code:
    gcc -o simple -lcurl simple.c
    ./simple
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Just Joined!
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    6
    thank you, that was the problem, your command compiled with no errors, now I can move on to make the prog do something for real

    have a good day

    tom

  8. #8
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I want to point out that the argument to -l is the library name, minus the prefix "lib". So when linking against math functions (stored in libm.so), you use "-lm". When linking against libvorbis, you use "-lvorbis". And when linking against libcurl, you use "-lcurl".
    DISTRO=Arch
    Registered Linux User #388732

  9. #9
    Just Joined!
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    6
    thank you for pointing that out. I have much to learn about compiling under gcc, a whole new toolset to play with. Things are much different than under Visual Studio

    tom

  10. #10
    Trusted Penguin Dapper Dan's Avatar
    Join Date
    Oct 2004
    Location
    The Sovereign State of South Carolina
    Posts
    4,562
    As you can see, I didn't really know much about your problem, but I figured if I kept the thread alive, one of the big guns like drl or Cabhan would eventually see it and respond and get you on the right track...
    Linux Mint + IceWM Registered:#371367 New Members: click here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...