Thread: Using Libcurl Dev C++ Undefined Reference Errors

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    26

    Using Libcurl Dev C++ Undefined Reference Errors

    ******SAMPLE CODE FOUND ON INTERNET:********* -compiler: devc++ 5.11 libcurl version: 7.60
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <curl/curl.h>
    #include <curl/types.h>
    #include <curl/easy.h>
    
    
    int main()
    {
    
    curl_global_init( CURL_GLOBAL_ALL );
    CURL * myHandle = curl_easy_init ( );
    
    // Set up a couple initial paramaters that we will not need to mofiy later.
    curl_easy_setopt(myHandle, CURLOPT_USERAGENT, "Mozilla/4.0");
    curl_easy_setopt(myHandle, CURLOPT_AUTOREFERER, 1 );
    curl_easy_setopt(myHandle, CURLOPT_FOLLOWLOCATION, 1 );
    curl_easy_setopt(myHandle, CURLOPT_COOKIEFILE, "");
    
    // Visit the login page once to obtain a PHPSESSID cookie
    curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.hackthissite.org/user/login/");
    // Next we tell LibCurl what HTTP POST data to submit
    char *data="username=your_username_here&password=your_password_here";
    curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, data);
    curl_easy_perform( myHandle );
    
    curl_easy_cleanup( myHandle );
    
    
    return 0;
    }
    **************ERRORS:*****************

    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.cpp [Error] curl/types.h: No such file or directory
    compilation terminated.
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Makefile.win recipe for target 'Untitled9.o' failed


    ********When I delete the "#include <curl/types.h>" from the code I get the following errors:********

    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.cpp In function 'int main()':

    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.cpp [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]

    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x15): undefined reference to `__imp_curl_global_init'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x1e): undefined reference to `__imp_curl_easy_init'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x3e): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x59): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x74): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x90): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0xac): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0xbc): undefined reference to `__imp_curl_easy_perform'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0xd8): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0xff): undefined reference to `__imp_curl_easy_setopt'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x10f): undefined reference to `__imp_curl_easy_perform'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.o Untitled9.cpp.text+0x11f): undefined reference to `__imp_curl_easy_cleanup'
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\collect2.exe [Error] ld returned 1 exit status
    C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Makefile.win recipe for target 'Project8.exe' failed



    How do I fix these undefined reference errors? Also, what is the equivalent of types.h header file in curl 7.60? This version of curl doesn't come with that header file.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.cpp
    Do NOT create your personal projects in the installation directories of packages you've downloaded.

    One false step, and you're wondering why NONE of your programs are working all of a sudden.

    > How do I fix these undefined reference errors?
    You need to edit your project linker settings, say
    settings -> linker -> additional libraries.

    You need to set
    - the name(s) of additional libraries
    - the search path(s) to those additional libraries
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    Great advice, it compiles now but it doesn't seem to do what I expected it to do? It should take the credentials I hard code in and log in to the site with them then input to the console, but it doesn't seem to do anything; it doesn't log in, I just get the blank console popping up. I did not write this code, I took it from a website, and this is obviously my first time using libcurl. What is supposed to happen?



    Quote Originally Posted by Salem View Post
    > C:\Users\b0600539\Downloads\Dev-Cpp\MinGW64\libcurl\Untitled9.cpp
    Do NOT create your personal projects in the installation directories of packages you've downloaded.

    One false step, and you're wondering why NONE of your programs are working all of a sudden.

    > How do I fix these undefined reference errors?
    You need to edit your project linker settings, say
    settings -> linker -> additional libraries.

    You need to set
    - the name(s) of additional libraries
    - the search path(s) to those additional libraries

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Well what do you expect to happen when you type in http://your.site.com/?username=your_..._password_here

    Your program is remarkably output free at the moment.

    Perhaps add some more curl opts to
    - display the data sent back
    - save cookie jars
    - enable 'verbose' logging to see what is going on.

    Many examples are rudimentary in the sense that they get you started. But unless it specifically says it will do exactly what you want out of the box, you need to do some thinking on your own as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    Alright, that's fair. Let's say I have an online dashboard, where I have to select certain options to get the data I want exported to Excel. There's an option from a drop down menu I want my program to select, then I want it to enter in hardcoded dates into two fields, and select a button that will export the data corresponding to that criteria to Excel. What types of curl functions would I be looking at to get those actions done?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Well I suggest you install wireshark and observe the entire conversion from a browser.

    You'll need to implement the message traffic that the browser sends and handle the responses.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Several, undefined reference to...
    By Or1gin in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2013, 06:02 PM
  2. compiler keeps giving undefined reference errors
    By ecsx00 in forum C Programming
    Replies: 1
    Last Post: 11-24-2011, 03:12 AM
  3. Replies: 20
    Last Post: 04-11-2011, 11:42 AM
  4. Linker Errors undefined reference to 'rand'
    By asic_designer in forum C++ Programming
    Replies: 11
    Last Post: 02-01-2011, 04:57 PM
  5. Replies: 7
    Last Post: 10-09-2007, 02:37 PM

Tags for this Thread