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 92 forks source link

Linking errors on ServerMember #196

Closed rasikhq closed 3 years ago

rasikhq commented 3 years ago

Hey, I've been using this library for quite a while now and recently ran into a weird issue.

Check out this sample code:

void Bot::onMessage(SleepyDiscord::Message message)
{
    if (message.author.bot) return;

    SleepyDiscord::ServerMember serverMember = getMember(message.serverID, message.author.ID);
}

Causes:

2>Bot.obj : error LNK2019: unresolved external symbol "public: __cdecl SleepyDiscord::ServerMember::ServerMember(class std::basic_string_view<char,struct std::char_traits<char> > const &)" (??0ServerMember@SleepyDiscord@@QEAA@AEBV?$basic_string_view@DU?$char_traits@D@std@@@std@@@Z) referenced in function "public: __cdecl SleepyDiscord::ObjectResponse<struct SleepyDiscord::ServerMember>::operator struct SleepyDiscord::ServerMember(void)" (??B?$ObjectResponse@UServerMember@SleepyDiscord@@@SleepyDiscord@@QEAA?AUServerMember@1@XZ)
2>build\bot\Release\DDiscord.dll : fatal error LNK1120: 1 unresolved externals

on GCC (When loading the DLL) image

The linking completely fails on MSVC. The project builds and links on GCC but throws an exception (similar to msvc) when loading the bot DLL so basically its failing on both MSVC and GCC.

Any help would be appreciated.

yourWaifu commented 3 years ago

can you try the develop version?

rasikhq commented 3 years ago

I was firstly on master, then I switched to develop and it still didn't resolve it.

yourWaifu commented 3 years ago

it looks like a c++ standards mismatch, can you make sure that the library and the program being linked are using the same c++ version or both are running C++ versions higher then 17.

rasikhq commented 3 years ago

Well changed my CMAKE config file to

set (CMAKE_CXX_STANDARD 20)

Both the program and sleepy-discord project are set to /std:c++latest (previously were /std:c++17)

and uhhhh funnily I'm getting more errors now.

yourWaifu commented 3 years ago

if you want to, you can try to enforce the use of string_view, there used to be a memory usage difference but not sure if that's still the case since a number of overhauls to json parsing. set the following preprocessor define for both the target and the shared library. nssv_CONFIG_SELECT_STD_STRING_VIEW defined here https://github.com/yourWaifu/sleepy-discord/blob/5682d4dc52d38ee16fb8f57fddf43d334467a360/include/sleepy_discord/nonstd/string_view.hpp#L24

rasikhq commented 3 years ago

Defined it for both the library and the program projects, still didn't help.

Just to mention that the extra errors are related to strings like

image

So at this point the library is failing to compile so the .lib isn't generating to link with the program.

yourWaifu commented 3 years ago

hmm might need to add #include <string> to the top of json_wrapper.cpp. or the wrong c++ version was set.

rasikhq commented 3 years ago

So I added the #include <string> in json_wrapper.cpp which got rid of the to_string error. However this is showing up when sleepy-discord.lib is being generated:

image

And then when I link sleepy-discord.lib with the program, it ends up failing because now there's a redefinition image

rasikhq commented 3 years ago

I don't know what happened but now it just compiled successfully. I haven't changed anything in terms of configuration and stuff... so yeah closing it but thanks for trying to help me out.