Help with linking libraries

2010-10-17
2012-09-26
  • Adesh Dsilva
    Adesh Dsilva
    2010-10-17

    I am using Dev-cpp - 7.3.1.3 On Windows XP

    I want to use curl in my project built using devcpp

    So I created a static library (project) in devcpp for the same.
    I have include all the necessary curl files in it.

    Then i created a console project,

    But i have no idea as to how to link to my static library

    While running the following code

    #define CURL_STATICLIB
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <curl/curl.h>
    #include <curl/easy.h>
    
    int main(void)
    {
      CURL *curl;
      CURLcode res;
    
      curl = curl_easy_init();
      if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "[url]http://example.com[/url]");
        res = curl_easy_perform(curl);
    
        /* always cleanup */ 
        curl_easy_cleanup(curl);
      }
      getch();
      return 0;
    }
    

    The compiler is giving me the following error

    [Linker Error] undefined reference to `curl_easy_init'
    [Linker Error] undefined reference to `curl_easy_setopt'
    [Linker Error] undefined reference to `curl_easy_perform'
    [Linker Error] undefined reference to `curl_easy_cleanup'
    ld returned 1 exit status
    E:\wamp\www\jm\yy\Makefile.win [Build Error]  [Output/MingW/Project4.exe] Error 1
    

    I tried to add the library (libcurl.a, libcurldll.a) and other libraries
    through

    1. Project->Add to Project
    2. Project->Project Options->Directories->Library Directories
    3. Tools-> Compiler Options->Directories->Libraries

    But nothing Works.

    ThankYOu

     
  • Steve A
    Steve A
    2010-12-01

    Try:

    1) click on the Projects ->"Project Options"->"Parameters"

    2) under "Linker", where it says: "Add Library or Object",
    click that button,

    3) scan across the list until you find the library you want to link,
    (**if libcurl.a is not in the default /lib/ folder, then select the correct
    folder),
    Double click on it,
    that will place libcurl.a in the linker list,
    repeat process for more libraries,

    4) click on the OK button to close that window,
    5) Under FILE, click on "Save All",
    6) Under Execute, click on "Rebuild All"

     
  • DARC
    DARC
    2011-06-14

    When you open the project are the librarys in the project?
    Sometimes the order the libraries are listed in projects affects linking, try
    swapping order of file.a and file.dll .
    I dont do much programing with libraries, but do you really need both the .a
    and .dll files, try using just the .a file.
    Is the library in the project directory? Try a copy of the library in project
    directory.