我使用 Mac,是 Xcode 和 C++ 的初学者。我使用 brew install cpprestsdk
安装了一个库。然后我将 Xcode 中的 header 搜索路径设置为 /usr/local/Cellar/cpprestsdk/2.9.1/include/cpprest
用于 Debug 和 Release 以便自动完成工作。
我正在努力学习本教程 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
安装
您需要将额外的 header 搜索路径设置为 /usr/local/include
.将同时找到 cpprestsdk
和 pplx
作为彼此的同龄人。然后使用这个:
#include <cpprest/http_client.h>
然后您将遇到 fatal error :找不到“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
关于c++ - 如何使用 Xcode 8.2.1 在我的项目中添加 cpprestsdk 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45437584/