Results 1 to 4 of 4

Thread: Compiling with libcurl

  1. #1
    Join Date
    Jun 2005
    Beans
    55

    Compiling with libcurl

    I'm trying to compile a program using libcurl. I installed libcurl3, but I'm not sure if this is the right package. I'm have this in my code:
    Code:
    #include <curl/curl.h>
    but I get a lot of error messages such as
    Code:
    getpage.c:16: error: ‘CURL’ undeclared (first use in this function)
    when I try to compile. Is the some compiler flag that I need to have on the command line when I compile?

  2. #2
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: Compiling with libcurl

    Hi,

    You need to install libcurl3-dev or libcurl4-dev to get the header files associated with the library.

    When compiling, you should pass $(pkg-config --cflags libcurl) to gcc. When linking, $(pkg-config --libs libcurl). If you are compiling and linking in one step you can do it like so:

    gcc myfile.c $(pkg-config --libs --cflags libcurl) -o myprogram

    Hope this helps.
    Here we are, trapped in the amber of the moment. There is no why.

  3. #3
    Join Date
    Apr 2006
    Beans
    Hidden!

    Re: Compiling with libcurl

    This works:

    Code:
    gcc myfile.c $(pkg-config --libs --cflags libcurl) -o myprogram
    But this would be easier to understand maybe?

    Code:
    gcc myfile.c -lcurl -o myprogram
    Maybe someone could describe how they are different?

  4. #4
    Join Date
    Aug 2008
    Beans
    32

    Re: Compiling with libcurl

    Quote Originally Posted by CannedCorn View Post
    This works:

    Code:
    gcc myfile.c $(pkg-config --libs --cflags libcurl) -o myprogram
    But this would be easier to understand maybe?

    Code:
    gcc myfile.c -lcurl -o myprogram
    Maybe someone could describe how they are different?
    Yes, that would be easier to understand but it hard codes the location of the curl library. It has to be in /usr/lib or /usr/local/lib since those are the default directories where gcc searches for libraries. What if I build the curl library from source and drop it in my home directory? This is the problem that the pkg-config program alleviates. When I build and install curl a pkg-config file is built based on where I installed curl then any other program can reference that file in order to include the headers or link to the libraries.

    Hope this clarifies things a little.

Bookmarks

Posting Permissions

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