#include <iostream>
#include <string>
#include "cpr/cpr.h"
int main()
{
cpr::Url URL{"http://localhost:3000"};
cpr::Header header{{"Content-Type", "application/json"}}; // This line gives me link errors
cpr::Response response{cpr::Get(URL)}; // This line gives me a seg fault
return 0;
}
If I leave in the line where I create a cpr::Header object, I get strange link errors:
====================[ Build | HashClient | Debug ]==============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/<my_name>/MyStuff/HashClient/cmake-build-debug --target HashClient
[2/2] Linking CXX executable HashClient
FAILED: HashClient
: && /usr/local/Cellar/gcc/13.1.0/bin/g++-13 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/HashClient.dir/main.cpp.o -o HashClient -Wl,-rpath,/usr/local/lib /usr/local/lib/libcpr.1.11.0.dylib ../vcpkg/installed/x64-osx/debug/lib/libcurl-d.a -framework SystemConfiguration -framework Security -framework CoreFoundation -framework CoreServices ../vcpkg/installed/x64-osx/debug/lib/libz.a && :
Undefined symbols for architecture x86_64:
"__ZNK3cpr22CaseInsensitiveCompareclERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_", referenced from:
__ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE29_M_get_insert_hint_unique_posESt23_Rb_tree_const_iteratorIS8_ERS7_ in main.cpp.o
__ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE10_M_insert_IRKS8_NSE_11_Alloc_nodeEEESt17_Rb_tree_iteratorIS8_EPSt18_Rb_tree_node_baseSM_OT_RT0_ in main.cpp.o
__ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE24_M_get_insert_unique_posERS7_ in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
If I don't bother with headers and try to make a simple get request, I get a segment fault Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) (with this being to an address I can navigate to in my browser).
I've got no idea what's gone wrong here. I've initially installed cpr using vcpgk (following the instructions in the readme), and when I encountered issues with that, I also cloned the cpr repo and built it locally (again, following the instructions in the readme). After googling around a little I also tried adding the lines
I'm trying to use cpr in a small CLion project on MacOS where I make http requests to a local server. My CMakeFiles.txt looks as follows :
and my
main.cpp
file looks as follows:If I leave in the line where I create a cpr::Header object, I get strange link errors:
If I don't bother with headers and try to make a simple get request, I get a segment fault
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
(with this being to an address I can navigate to in my browser).I've got no idea what's gone wrong here. I've initially installed cpr using vcpgk (following the instructions in the readme), and when I encountered issues with that, I also cloned the cpr repo and built it locally (again, following the instructions in the readme). After googling around a little I also tried adding the lines
to my cmakeslists.txt but this didn't change anything.
Where did you get it from?
vcpkg
Additional Context/Your Environment
MacOS Ventura 13.6