首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C++编译cpr

C++编译cpr
EN

Stack Overflow用户
提问于 2019-12-30 20:53:52
回答 2查看 2.2K关注 0票数 0

我试图使用心肺复苏发送HTTP请求,但是我可以‘编译它,所以我的应用程序的编译器返回:

代码语言:javascript
运行
复制
1>Send.obj : error LNK2019: symbole externe non résolu "public: __cdecl cpr::Session::Session(void)" (??0Session@cpr@@QEAA@XZ) référencé dans la fonction "class cpr::Response __cdecl cpr::Get<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &&)" (??$Get@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@cpr@@YA?AVResponse@0@$$QEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

在github上,关于如何编译的文档不多,所以我尝试使用CMake,但它也返回了一个错误:

代码语言:javascript
运行
复制
C++ Requests CMake Options
=======================================================
  USE_SYSTEM_CURL: OFF
  BUILD_CPR_TESTS: ON
  GENERATE_COVERAGE: OFF
  CPR_CURL_NOSIGNAL: OFF
  USE_SYSTEM_GTEST: OFF
  CMAKE_USE_OPENSSL: ON
=======================================================
Not using system Curl, using built-in curl project instead.
CMake Error at opt/CMakeLists.txt:48 (add_subdirectory):
  The source directory

    D:/Developpement/C++/cpr-master/opt/curl

  does not contain a CMakeLists.txt file.


CMake Error at opt/CMakeLists.txt:60 (set_property):
  set_property could not find TARGET libcurl.  Perhaps it has not yet been
  created.


Set CURL_FOUND to TRUE.
Set CURL_LIBRARIES to libcurl.
Set CURL_INCLUDE_DIRS to /include;/include/curl.
Not using system gtest, using built-in googletest project instead.
CMake Error at opt/CMakeLists.txt:82 (add_subdirectory):
  The source directory

    D:/Developpement/C++/cpr-master/opt/googletest

  does not contain a CMakeLists.txt file.


CMake Error at opt/CMakeLists.txt:90 (set_property):
  set_property could not find TARGET gtest.  Perhaps it has not yet been
  created.


CMake Error at opt/CMakeLists.txt:91 (set_property):
  set_property could not find TARGET gtest_main.  Perhaps it has not yet been
  created.


Set GTEST_FOUND to TRUE.
Set GTEST_LIBRARIES to gtest.
Set GTEST_MAIN_LIBRARIES to gtest_main.
Set GTEST_BOTH_LIBRARIES to gtest;gtest_main.
Set GTEST_INCLUDE_DIRS to /include.
Building mongoose project for test support.
CMake Error at opt/CMakeLists.txt:106 (add_subdirectory):
  The source directory

    D:/Developpement/C++/cpr-master/opt/mongoose

  does not contain a CMakeLists.txt file.


Set MONGOOSE_FOUND to TRUE.
Set MONGOOSE_LIBRARIES to mongoose.
Set MONGOOSE_INCLUDE_DIRS to .
CMake Error at opt/CMakeLists.txt:116 (set_property):
  set_property could not find TARGET mongoose.  Perhaps it has not yet been
  created.


Using CURL_INCLUDE_DIRS: /include;/include/curl.
Using CURL_LIBRARIES: libcurl.
Configuring incomplete, errors occurred!
See also "D:/Developpement/C++/cpr-master/build/CMakeFiles/CMakeOutput.log".
See also "D:/Developpement/C++/cpr-master/build/CMakeFiles/CMakeError.log".

我也尝试了gcc,但他们没有说我们必须包括哪些文件,它返回的头部没有找到任何方式。有人能描述一下复制CPR的步骤吗?还是另一种发送HTTP请求的简单方法?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-26 10:53:30

使用git clone --recursive https://github.com/whoshuu/cpr/而不是git clone https://github.com/whoshuu/cpr/

票数 1
EN

Stack Overflow用户

发布于 2019-12-30 21:32:52

有关于github 这里的文档。

为了启动和运行这个库,我强烈建议分叉这个示例项目。它配置了最低限度的CMake魔术和样板,以开始玩网络应用程序。 如果您已经有了一个需要集成C++请求的项目,主要的方法是使用git子模块。将此存储库添加为根存储库的子模块: git子模块添加git@github.com:whoshuu/cpr.git或git子模块添加https://github.com/whoshuu/cpr.git git子模块更新-init-递归 接下来,在声明任何可能使用该子目录的目标之前,将该子目录添加到CMakeLists.txt中: 心肺复苏(Add_subdirectory) 这将产生两个重要的CMake变量,CPR_INCLUDE_DIRS和CPR_LIBRARIES,您将以典型的方式使用这两个变量: include_directories(${CPR_INCLUDE_DIRS}) target_link_libraries(your_target_name ${CPR_LIBRARIES}) 这应该就行了!使用集成C++请求的子模块方法,不需要自己处理libcurl,所有这些依赖都由您来处理。

(附带注意:您应该检查c++包管理器,比如conan或vcpkg,看看它们是否捆绑在一起,可能更容易设置)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59536740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档