首页 > 解决方案 > C++ 编译 cpr

问题描述

我正在尝试使用CPR发送 HTTP 请求,但我无法编译它,因此我的应用程序的编译器返回:

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,但它也返回一个错误:

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 请求的简单方法?谢谢

标签: c++cmake

解决方案


使用git clone --recursive https://github.com/whoshuu/cpr/代替git clone https://github.com/whoshuu/cpr/


推荐阅读