yourWaifu / sleepy-discord

C++ library for the Discord chat client. Please use Rust for new bots
https://yourWaifu.github.io/sleepy-discord/
MIT License
707 stars 95 forks source link

Compilation of the Hello Example doesn't work or something? #102

Closed jimisdam closed 6 years ago

jimisdam commented 6 years ago

I followed the steps for compiling the source and when I compile the example hello, I get this:

> ➜  hello g++ -std=c++11 -I ../../include -I ../../deps -I ../../deps/include -I ../../include/sleepy_discord/IncludeNonexistent example0.cpp -L../../buildtools -L/usr/lib -lsleepy_discord -lcurl -lssl -lcrypto -lpthread -o example.out
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::setUrl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession6setUrlERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN13SleepyDiscord10CPRSession6setUrlERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x37): undefined reference to `cpr::Session::SetUrl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::setBody(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*)':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession7setBodyEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN13SleepyDiscord10CPRSession7setBodyEPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x37): undefined reference to `cpr::Session::SetBody(cpr::Body&&)'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::Post()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession4PostEv[_ZN13SleepyDiscord10CPRSession4PostEv]+0x33): undefined reference to `cpr::Session::Post()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::Patch()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession5PatchEv[_ZN13SleepyDiscord10CPRSession5PatchEv]+0x33): undefined reference to `cpr::Session::Patch()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::Delete()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession6DeleteEv[_ZN13SleepyDiscord10CPRSession6DeleteEv]+0x33): undefined reference to `cpr::Session::Delete()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::Get()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession3GetEv[_ZN13SleepyDiscord10CPRSession3GetEv]+0x33): undefined reference to `cpr::Session::Get()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::Put()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSession3PutEv[_ZN13SleepyDiscord10CPRSession3PutEv]+0x33): undefined reference to `cpr::Session::Put()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::CPRSession()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSessionC2Ev[_ZN13SleepyDiscord10CPRSessionC5Ev]+0x33): undefined reference to `cpr::Session::Session()'
client.cpp:(.text._ZN13SleepyDiscord10CPRSessionC2Ev[_ZN13SleepyDiscord10CPRSessionC5Ev]+0x5a): undefined reference to `cpr::Multipart::Multipart(std::initializer_list<cpr::Part> const&)'
client.cpp:(.text._ZN13SleepyDiscord10CPRSessionC2Ev[_ZN13SleepyDiscord10CPRSessionC5Ev]+0xa6): undefined reference to `cpr::Session::~Session()'
../../buildtools/libsleepy_discord.a(client.o): In function `SleepyDiscord::CPRSession::~CPRSession()':
client.cpp:(.text._ZN13SleepyDiscord10CPRSessionD2Ev[_ZN13SleepyDiscord10CPRSessionD5Ev]+0x34): undefined reference to `cpr::Session::~Session()'
../../buildtools/libsleepy_discord.a(cpr_session.o): In function `SleepyDiscord::CPRSession::setHeader(std::vector<SleepyDiscord::HeaderPair, std::allocator<SleepyDiscord::HeaderPair> > const&)':
cpr_session.cpp:(.text+0x11e): undefined reference to `cpr::Session::SetHeader(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
../../buildtools/libsleepy_discord.a(cpr_session.o): In function `SleepyDiscord::CPRSession::setMultipart(std::initializer_list<SleepyDiscord::Part> const&)':
cpr_session.cpp:(.text+0x35d): undefined reference to `cpr::Session::SetMultipart(cpr::Multipart const&)'
../../buildtools/libsleepy_discord.a(cpr_session.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, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_get_insert_unique_pos(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
cpr_session.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE24_M_get_insert_unique_posERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE24_M_get_insert_unique_posERS7_]+0x64): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
cpr_session.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE24_M_get_insert_unique_posERS7_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE24_M_get_insert_unique_posERS7_]+0x11f): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
../../buildtools/libsleepy_discord.a(cpr_session.o): In function `std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > 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, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_insert_<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, 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, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Alloc_node>(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&&, 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, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cpr::CaseInsensitiveCompare, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Alloc_node&)':
cpr_session.cpp:(.text._ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE10_M_insert_IS8_NSE_11_Alloc_nodeEEESt17_Rb_tree_iteratorIS8_EPSt18_Rb_tree_node_baseSK_OT_RT0_[_ZNSt8_Rb_treeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_S5_ESt10_Select1stIS8_EN3cpr22CaseInsensitiveCompareESaIS8_EE10_M_insert_IS8_NSE_11_Alloc_nodeEEESt17_Rb_tree_iteratorIS8_EPSt18_Rb_tree_node_baseSK_OT_RT0_]+0x68): undefined reference to `cpr::CaseInsensitiveCompare::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
collect2: error: ld returned 1 exit status

What's wrong with it? I'm using Fedora 28.

yourWaifu commented 6 years ago

It looks like you didn't link cpr, compile it and link (adding ../../deps/cpr/cpr/*.cpp should also work).

jimisdam commented 6 years ago

Thank you a lot, it worked! But, why would this happen, even following the given steps?

yourWaifu commented 6 years ago

Here how I understand it. take a look at this code.

void exampleFunction();

int main() {
    exampleFunction();
}

Although, this is valid code if exampleFunction is defined later. However, afterwards the linker will look for the definition of exampleFunction and not find it so it gives an similar to what you see above. Fixing this is very simple.

void exampleFunction();

int main() {
    exampleFunction();
}

void exampleFunction() {
    int a = 4;
    a = 3;
}