2017-04-21 129 views
1

我想添加curlpp到我的C++项目。目前,我有一个的main.cpp文件,它看起来像这样:如何添加库curlpp到C++项目

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

int main() { 
    return 0; 
} 

予编译使用: “克++ -std = C++ 14 -I/USR/nguyenthesang /桌面/ myprogram/curlpp-0.8 .1/include main.cpp“并成功编译。

然后,添加在主函数的实现(下面从curlpp的回购复制):

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


using namespace curlpp::options; 

int main(int, char **) 
{ 
    try 
    { 
    // That's all that is needed to do cleanup of used resources (RAII 
    style). 
    curlpp::Cleanup myCleanup; 

    // Our request to be sent. 
    curlpp::Easy myRequest; 

    // Set the URL. 
    myRequest.setOpt<Url>("http://example.com"); 

    // Send request and get a result. 
    // By default the result goes to standard output. 
    myRequest.perform(); 
} 

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

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

return 0; 
} 

当我编译通过使用“克++ -std = C++ 14 -I/USR/nguyenthesang/Desktop/myprogram/curlpp-0.8.1/include main.cpp“,存在编译错误,说”ld:symbol(s)not found for architecture x86_64 clang:error:linker command failed with exit代码1(使用-v来查看调用)“。

这些错误可能来自于我只将头文件链接到程序而不是库本身的事实。我谷歌周围找到链接库的方式(例如使用-L选项),但它没有工作。我需要这个问题的帮助。

我也想问一下,是否有一种将每个库添加到C++项目中的通用方法,例如iOS中的Cocoapods?

我感谢您的帮助。

回答

1

您应该下载完整的源代码包(downloads部分的.tar.gz)以获取标题,代码,示例和文档。

您需要将包含文件所在机器的基本目录(打开归档文件包之后)添加到项目的包含目录列表中。

+0

您能否详细解释如何将libs的路径添加到项目的目录中?我 –

+0

你有没有添加我告诉你下载的目录 – Billa

+0

我下载了你所说的软件包,并做了同样的事情。发生同样的问题。 –