Reputation: 53
I'm trying to use CPR to send HTTP requests, but I can' compile it, so compiler for my app returns :
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)
On github, there is not that much documentation on how to compile, so I tried with CMake but it returns also an error :
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".
I also tried with gcc, but they don't say which files we have to include, and it returns that the headers are not found anyways. Could somebody describe the steps to reproduce to compile CPR please ? Or another easy way to send HTTP requests ? Thanks
Upvotes: 0
Views: 2928
Reputation: 26
Use git clone --recursive https://github.com/whoshuu/cpr/
instead of git clone https://github.com/whoshuu/cpr/
Upvotes: 1
Reputation: 2533
There is documentation on github here.
For just getting this library up and running, I highly recommend forking the example project. It's configured with the minimum CMake magic and boilerplate needed to start playing around with networked applications.
If you already have a project you need to integrate C++ Requests with, the primary way is to use git submodules. Add this repository as a submodule of your root repository:
git submodule add [email protected]:whoshuu/cpr.git OR git submodule add https://github.com/whoshuu/cpr.git
git submodule update --init --recursive
Next, add this subdirectory to your CMakeLists.txt before declaring any targets that might use it:
add_subdirectory(cpr)
This will produce two important CMake variables, CPR_INCLUDE_DIRS and CPR_LIBRARIES, which you'll use in the typical way:
include_directories(${CPR_INCLUDE_DIRS}) target_link_libraries(your_target_name ${CPR_LIBRARIES})
and that should do it! Using the submodule method of integrating C++ Requests, there's no need to handle libcurl yourself, all of those dependencies are taken care of for you.
(Side note : you should check c++ package managers like conan, or vcpkg to see if it's bundled in them, might be easier to set up)
Upvotes: 0