cpr
cpr copied to clipboard
Linker error when using cpr via vcpkg on windows
Description
I installed cpr via vcpkg. Trying to compile and link a very simple program using cpr. Linking gives the following error:
C:\Users\bigshaQ\Desktop\lilium>g++ main.o -LC:/Users/bigshaQ/Desktop/vcpkg/installed/x64-windows/lib -lcpr -o main
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text$_ZN3cpr3GetIJNS_3UrlEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIJNS_3UrlEEEENS_8ResponseEDpOT_]+0x27): undefined reference to `cpr::Session::Session()'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text$_ZN3cpr3GetIJNS_3UrlEEEENS_8ResponseEDpOT_[_ZN3cpr3GetIJNS_3UrlEEEENS_8ResponseEDpOT_]+0x58): undefined reference to `cpr::Session::Get()'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text$_ZN3cpr4priv19set_option_internalILb0ENS_3UrlEEEvRNS_7SessionEOT0_[_ZN3cpr4priv19set_option_internalILb0ENS_3UrlEEEvRNS_7SessionEOT0_]+0x27): undefined reference to `cpr::Session::SetOption(cpr::Url const&)'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o:main.cpp:(.text$_ZNSt4pairIKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3cpr21EncodedAuthenticationEED1Ev[_ZNSt4pairIKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEN3cpr21EncodedAuthenticationEED1Ev]+0x18): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
collect2.exe: error: ld returned 1 exit status
Example/How to Reproduce
Compiling and then linking the following program caused the error mentioned above
#include <cpr/cpr.h>
#include <iostream>
int main(){
cpr::Response res = cpr::Get(cpr::Url{"https://mainnet-api.algonode.network"});
std::cout << res.status_code << std::endl;
return 0;
}
Possible Fix
No response
Where did you get it from?
vcpkg
Additional Context/Your Environment
- OS: windows11
@Drollex thanks for reporting! This is a vcpkg issue and we do not support vcpkg.
Never the less I suspect you did not correctly install cpr via vcpkg. Try vcpkg install cpr --triplet=x64-mingw-dynamic
Else here is a example if you are willing to use CMake: https://github.com/libcpr/example-cmake-fetch-content