libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.49k stars 922 forks source link

Linker error when using cpr via vcpkg on windows #1114

Open Drollex opened 4 days ago

Drollex commented 4 days ago

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

COM8 commented 3 days ago

@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