0

I've started working with libcurl for couple hours. But it occurs too many errors at once. This is my code in main.cpp:

#include <iostream>
#include "curl-7.53.1/include/curl/curl.h"
using namespace std;

int main(int argc, char *argv[])
{
    CURL *curl;
    CURLcode res;
    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();
    if(curl){
        curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/like.php");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "mediaId=4665");
        res = curl_easy_perform(curl);
        if(res!=CURLE_OK)
            cout«"something went wrong.";
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
    return 0;
}

So these are the errors:

/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_global_init'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_easy_init'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_easy_setopt'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_easy_setopt'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_easy_perform'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_easy_cleanup'
/home/muhammad/Documents/Qt projects/untitled3/main.cpp:-1: error: undefined reference to `curl_global_cleanup'

How can I solve them? (OS is linux ubuntu)

Jens
  • 6,173
  • 2
  • 24
  • 43
no_ideaw
  • 151
  • 2
  • 10
  • I assume: these are errors when you `make`. IMHO these are link errors because `libcurl` is not considered as link library in the `make` script which you probably generated with `qmake`. If I'm right you can 1. edit Makefile by hand to add the missing dependency to `libcurl` (resp. its correct name) and 2. google about `qmake` to add dependency to `libcurl`. (Sorry, that I'm not more precise. `qmake` is for me new also.) – Scheff's Cat Apr 13 '17 at 07:48
  • By googling "qmake extern libs" I found [SO: How to add external libraries to qt4 application c++](https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwizyd_K-6DTAhXDL8AKHcG3DpEQFggcMAA&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F5314735%2Fhow-to-add-external-libraries-to-qt4-application-c&usg=AFQjCNHOK4T-7xr7XaT9SLGQwYC966AV1Q) and the Qt doc. [Third Party Libraries](http://doc.qt.io/qt-5/third-party-libraries.html). This should help. – Scheff's Cat Apr 13 '17 at 08:03
  • I just recognized that your source has actually nothing to do with Qt. (Sorry, but why did you tag this with [qt](http://stackoverflow.com/questions/tagged/qt)?) If you compile with gcc on command line, you have to add something like `-lcurl`. – Scheff's Cat Apr 13 '17 at 08:07

0 Answers0