在 kubuntu 上使用 code::blocks 对 curlpp 的未定义引用

Undefined reference to curlpp using code::blocks on kubuntu

我对 curlpp 库有疑问。我将解释我遵循的步骤。


第一步:下载安装

下载网址:Download

$./configure
$make
$sudo make install

第 2 步:我使用了以下代码:

#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

错误


如图所示添加-lcurlpp后:出现如下错误:

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

编译和 link 编译代码时,您需要 link 和 -lcurlpp

使用 Eclipse,我从未让 curlpp example01 正常工作。即使在尝试设置链接器和包含之后。但我能够从终端编译它:

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

因此,如果 Eclipse 不适合您,我建议您尝试使用终端。