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

步骤1:下载并安装

下载网站:Download

$./configure
$make
$sudo make install
  • curlpp头文件位于 / usr / local / include /
  • curlpp库文件位于 / usr / local / lib /



  • 步骤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
    

    错误
  • 对curlpp的 undefined reference ::: Easy:Easy()
  • 对curlpp的 undefined reference ::escape(const std::string&)
  • 对curlpp的 undefined reference ::容易:: setopt(curlpp OptionBase::*)
  • 对curlpp的 undefined reference curlpp::Easy::setopt(curlpp OptionBase::*)


  • 如图所示添加-lcurlpp后:我得到以下错误:

    最佳答案

    编译和链接代码时,需要与-lcurlpp链接。

    关于c++ - 在Kubuntu上使用code::blocks未定义对curlpp的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29119357/

    10-11 14:20