2
votes

I have a problem with curlpp library. I'll explain the steps that I followed.


Step 1: download and installation

download website: Download

$./configure
$make
$sudo make install
  • curlpp header files are located in /usr/local/include/
  • curlpp library files are located in /usr/local/lib/

Step 2: I used the following code:

#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>


using namespace std;

int main()
{
    char *url = (char*) "http://dbpedia.org/sparql";

    string queryString = "PREFIX dbp: <http://dbpedia.org/resource/> "
        "PREFIX dbp2: <http://dbpedia.org/ontology/> "
        "SELECT ?abstract "
        "WHERE { "
            "dbp:Nikola_Tesla dbp2:abstract ?abstract . "
            "FILTER langMatches(lang(?abstract), 'en')"
        "}";

    try
    {
        curlpp::Easy request;
        string parameters = "query=" + curlpp::escape(queryString);

        request.setOpt(new curlpp::options::Url(url));
        request.setOpt(new curlpp::options::Verbose(true));
        request.setOpt(new curlpp::options::PostFields(parameters));

        request.perform();
    }

    catch (curlpp::RuntimeError & e)
    {
        std::cout << e.what() << std::endl;
    }

    catch (curlpp::LogicError & e)
    {
        std::cout << e.what() << std::endl;
    }
    return 0;

}//end function main

Errors

  • Undefined reference to curlpp ::Easy:Easy()
  • Undefined reference to curlpp ::escape (const std :: string &)
  • Undefined reference to curlpp ::Easy::setopt (curlpp OptionBase :: *)
  • Undefined reference to curlpp curlpp::Easy::setopt(curlpp OptionBase:: *)
  • etc.

After adding -lcurlpp as the picture shows: I got the following errors: picture 1

g++ -LSQLiteCpp-master/debug -o bin/Debug/EntityLinking obj/Debug/DataLoader.o obj/Debug/Entity.o obj/Debug/Fact.o obj/Debug/FactClass.o obj/Debug/Link.o obj/Debug/main.o obj/Debug/ManageDb.o obj/Debug/SQLiteCpp-master/sqlite3/sqlite3.o obj/Debug/tinyxml/tinystr.o obj/Debug/tinyxml/tinyxml.o obj/Debug/tinyxml/tinyxmlerror.o obj/Debug/tinyxml/tinyxmlparser.o -lpthread -ldl -lcurlpp SQLiteCpp-master/debug/libSQLiteCpp.a /usr/bin/ld: obj/Debug/main.o: référence au symbole non défini «curl_easy_setopt@@CURL_OPENSSL_3» //usr/lib/x86_64-linux-gnu/libcurl.so.4: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Process terminated with status 1 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

2
have you tried curl-config --libs, or pkg-config --libs curl on the command line? Or have you tried to add -lssl as a linker flag?Arne
I added -lcurl witth -lcurlpp to the other linking options it actually solved the problem but I don't know why and how to explain itHani Goc

2 Answers

1
votes

You need to link with -lcurlpp when compiling & linking your code.

0
votes

Using Eclipse, I never got curlpp example01 working. Even after trying to set up the linkers and the includes. But I was able to compile it from a terminal:

g++ -o exe_name exe_name.cpp -L/usr/local/lib -lcurl -lcurlpp -I/usr/local/include

So I would suggest trying the terminal if Eclipse doesn't work for you.