libcpr / cpr

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

Linker error #920

Closed GEOEGII555 closed 1 year ago

GEOEGII555 commented 1 year ago

Description

I'm trying to build my program, but I get a linker error. The error:

geoegii555@DESKTOP-HK0PRA8:nodirforu$ make
mkdir -p out
g++ -lm -L ./cpr/lib -L ./cpr/build/lib -lcpr -lcurl -std=c++17 -Ofast main.cpp -o out/main
/usr/bin/ld: /tmp/ccF1dZPZ.o: in function `main':
main.cpp:(.text.startup+0x315): undefined reference to `cpr::Session::Session()'
/usr/bin/ld: main.cpp:(.text.startup+0x320): undefined reference to `cpr::Session::SetOption(cpr::Url const&)'
/usr/bin/ld: main.cpp:(.text.startup+0x330): undefined reference to `cpr::Session::Get()'
/usr/bin/ld: /tmp/ccF1dZPZ.o: in function `std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, cpr::EncodedAuthentication>, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, cpr::EncodedAuthentication> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, cpr::EncodedAuthentication> > >::_M_erase(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, cpr::EncodedAuthentication> >*) [clone .isra.0]':
main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0xb4): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
/usr/bin/ld: main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0xfc): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
/usr/bin/ld: main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0x143): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
/usr/bin/ld: main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0x1a9): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
/usr/bin/ld: main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0x1ee): undefined reference to `cpr::EncodedAuthentication::~EncodedAuthentication()'
/usr/bin/ld: /tmp/ccF1dZPZ.o:main.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_N3cpr21EncodedAuthenticationEESt10_Select1stISA_ESt4lessIS5_ESaISA_EE8_M_eraseEPSt13_Rb_tree_nodeISA_E.isra.0[_ZN3cpr7SessionD5Ev]+0x239): more undefined references to `cpr::EncodedAuthentication::~EncodedAuthentication()' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:7: build] Error 1

Example/How to Reproduce

  1. Try to compile your program
  2. Here's my makefile:
    
    ARGS=-lm -L ./cpr/lib -L ./cpr/build/lib -lcpr -lcurl -std=c++17

default: build

build: main.cpp mkdir -p out g++ $(ARGS) -Ofast main.cpp -o out/main

clean: rm -rf out

3. Get the linker error!

### Possible Fix

_No response_

### Where did you get it from?

GitHub (branch e.g. master)

### Additional Context/Your Environment

I use WSL on Windows 11 (distro inside WSL: Ubuntu)

geoegii555@DESKTOP-HK0PRA8:/nodirforu$ neofetch .-/+oossssoo+/-. geoegii555@DESKTOP-HK0PRA8 :+ssssssssssssssssss+: -------------------------- -+ssssssssssssssssssyyssss+- OS: Ubuntu 22.04.2 LTS on Windows 10 x86_64 .ossssssssssssssssssdMMMNysssso. Kernel: 5.15.90.1-microsoft-standard-WSL2 /ssssssssssshdmmNNmmyNMMMMhssssss/ Uptime: 2 hours, 2 mins +ssssssssshmydMMMMMMMNddddyssssssss+ /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Packages: 800 (dpkg), 6 (snap) .ssssssssdMMMNhsssssssssshNMMMdssssssss. Shell: bash 5.1.16 +sssshhhyNMMNyssssssssssssyNMMMysssssss+ Theme: Adwaita [GTK3] ossyNMMMNyMMhsssssssssssssshmmmhssssssso Icons: Adwaita [GTK3] ossyNMMMNyMMhsssssssssssssshmmmhssssssso Terminal: Relay(371) +sssshhhyNMMNyssssssssssssyNMMMysssssss+ CPU: Intel i7-8565U (8) @ 1.992GHz .ssssssssdMMMNhsssssssssshNMMMdssssssss. GPU: 3604:00:00.0 Microsoft Corporation Device 008e /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/ Memory: 498MiB / 7853MiB +sssssssssdmydMMMMMMMMddddyssssssss+ /ssssssssssshdmNNNNmyNMMMMhssssss/ .ossssssssssssssssssdMMMNysssso. -+sssssssssssssssssyyyssss+- :+ssssssssssssssssss+: .-/+oossssoo+/-.

COM8 commented 1 year ago

How did you install cpr?

GEOEGII555 commented 1 year ago
git clone cpr
cd cpr
mkdir build
cd build
cmake ..
make && make install
GEOEGII555 commented 1 year ago

Is this the correct way? @COM8

COM8 commented 1 year ago

Looks good. I'm going to look into if I can reproduce it. To me it looks like a broken lib path.

GEOEGII555 commented 1 year ago

I fixed the error, I putted the -l... args at the end Before: g++ -lm -lssl -lcrypto -lcurl -lcpr -L ./cpr/build/lib -Ofast main.cpp -o out/main After: g++ -lm -Ofast main.cpp -o out/main -lssl -lcrypto -lcurl -lcpr -L ./cpr/build/lib

But there's still may be an issue, since it's weird that I had to put it all at the end

COM8 commented 1 year ago

Glad you managed to fix it! But this is than no cpr issue any more but instead a g++ related requirement.

GEOEGII555 commented 1 year ago

The linker says it's an error inside cpr if I put it before, I don't know if it's really a gcc problem or a library problem

ср, 21 июн. 2023 г., 22:05 Fabian Sauter @.***>:

Glad you managed to fix it! But this is than no cpr issue any more but instead a g++ related requirement.

— Reply to this email directly, view it on GitHub https://github.com/libcpr/cpr/issues/920#issuecomment-1601333635, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANYAWP77FXY344VRS7OHGGTXMMZUZANCNFSM6AAAAAAZNSUFRM . You are receiving this because you authored the thread.Message ID: @.***>

GEOEGII555 commented 1 year ago

If it's actually an error inside gcc and not the library bugging out due to things being linked before/after the library, then add the note to the README or common issues page to avoid such issues again

COM8 commented 1 year ago

It is not a problem with g++ nor with cpr since it is a simple g++ order requirement for arguments.

https://stackoverflow.com/a/40602724

Adding it to the README would be an option but perhaps we should add a "Common Issues" section or something.

COM8 commented 1 year ago

Closing it for now.