c++include-pathcurlpp

Undefined reference to curlpp using code::blocks on kubuntu


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

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


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))


Solution

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