如何使用 Xcode 8.2.1 在我的项目中添加 cpprestsdk 库

How do I add the cpprestsdk library in my project using Xcode 8.2.1

本文关键字:项目 添加 cpprestsdk 我的 Xcode 何使用      更新时间:2023-10-16

我在Mac上,是Xcode和C++的初学者。我已经使用brew install cpprestsdk安装了一个库。然后,我将 Xcode 中的标头搜索路径设置为调试和发布/usr/local/Cellar/cpprestsdk/2.9.1/include/cpprest,以便自动完成工作。

我正在尝试遵循本教程 https://github.com/Microsoft/cpprestsdk/wiki/Getting-Started-Tutorial 所以我写了一个小程序:

#include <iostream>
#include <http_client.h>
#include <filestream.h>
int main(int argc, const char * argv[]) {
return 0;
}

但是当我尝试运行该程序时,我得到一个"词法或预处理器问题"pplx/pplxtasks.h指出http_client中找不到该文件。我缺少一个步骤吗?

我使用brew install cpprestsdk安装

您需要将额外的标题搜索路径设置为/usr/local/include。会发现cpprestsdkpplx都是彼此的对等体。然后使用这个:

#include <cpprest/http_client.h>

然后,您将遇到致命错误:"未找到openssl/conf.h"文件 请参阅 https://github.com/Microsoft/cpprestsdk/issues/458

。导致需要具有如下所示的标题搜索路径:/usr/local/include; /usr/local/opt/openssl/include

和库搜索路径,如下所示:/usr/local/opt/cpprestsdk/lib; /usr/local/opt/openssl/lib; /usr/local/opt/boost/lib

和额外的链接器标志,如下所示:-lcpprest -lssl -lcrypto -lboost_system -lboost_thread-mt -lboost_chrono-mt