Ask Your Question
0

Problems using curl using Qtcreator (ROS-KINETIC)

asked 2018-03-06 05:43:03 -0500

Solrac3589 gravatar image

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/c5d7... (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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-09-09 13:41:35 -0500

duck-development gravatar image

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

Something like this

target_link_libraries(MyExecutable curlpp)

source

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-03-06 05:43:03 -0500

Seen: 139 times

Last updated: Sep 09