我想将 curlpp 添加到我的 C++ 项目中。目前,我有一个 main.cpp 文件,如下所示:
#include <iostream>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
int main() {
return 0;
}
我使用: “g++ -std=c++14 -I/usr/nguyenthesang/Desktop/myprogram/curlpp-0.8.1/include main.cpp”编译,它成功编译。
然后我在主函数中添加实现(下面是从 curlpp 的 repo 复制的):
#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;
}
当我使用"g++ -std=c++14 -I/usr/nguyenthesang/Desktop/myprogram/curlpp-0.8.1/include main.cpp"进行编译时,会出现编译错误,即“ ld: symbol( s) 未找到架构 x86_64 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) “。
错误可能来自我只将头文件链接到程序而不是库本身的事实。我四处搜索以找到链接库的方法(例如使用 -L 选项),但它不起作用。我需要帮助解决这个问题。
我还想问一下,有没有一种通用的方法可以将每个库添加到 C++ 项目中,比如 iOS 中的 Cocoapods?
我感谢您的帮助。