Robotics StackExchange | Archived questions

Problems using curl using Qtcreator (ROS-KINETIC)

Hello everybody. I came here after doing research in this web (and others) and not finding a clear solution for me in the topic.

I am sorry if it is duplicated, but is searched this info a few times in the searcher and by tag (curl) and i did not find anything.

I have downloaded curl

sudo aptitude install libcurl4-openssl-dev

and I tried to do a small demo based on https://gist.github.com/alghanmi/c5d7b761b2c9ab199157 (which worked correctly outside ROS)

but doing it with ROS and QTCREATOR:

#include <ros/ros.h>
#include <iostream>
#include <string>
#include <curl/curl.h>

static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(int argc, char** argv)

{
    ros::init(argc, argv, "Try");

      CURL *curl;
      CURLcode res;
      std::string readBuffer;

      curl = curl_easy_init();
      if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);

        std::cout << readBuffer << std::endl;
      }


    ros::spin();

    return 0;
}

It does not recognise many of the curl functions:

listener.cpp:(.text+0x3219): undefined reference to `curl_easy_init' 
listener.cpp:(.text+0x324c): undefined reference to `curl_easy_setopt' 
listener.cpp:(.text+0x326a): undefined reference to `curl_easy_setopt' 
listener.cpp:(.text+0x328a): undefined reference to `curl_easy_setopt' 
listener.cpp:(.text+0x3299): undefined reference to `curl_easy_perform'
listener.cpp:(.text+0x32ae): undefined reference to `curl_easy_cleanup'

curl library itself is found, and using control+click into the actions, it redirects to the desired definition.

Maybe is somethin simple, but i do not manage to understand the problem.

Thanks

Asked by Solrac3589 on 2018-03-06 06:43:03 UTC

Comments

Answers

You have to add libcurl in you cmake file as link dependency.

Something like this

target_link_libraries(MyExecutable curlpp)

source

Asked by duck-development on 2019-09-09 13:41:35 UTC

Comments