Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working on Windows...? #241

Open
Gazoo101 opened this issue Aug 27, 2021 · 19 comments
Open

Working on Windows...? #241

Gazoo101 opened this issue Aug 27, 2021 · 19 comments

Comments

@Gazoo101
Copy link

First and foremost - this library looks like just what I've been searching for. Thank you very much for all the effort made thus far.

However, I'm unable to get it do seemingly do anything on Windows. I've compiled the code into my project and it seems to compile fine but even the basic example appears to do nothing (and also be a bit out of date on the master branch)

https://github.com/yourWaifu/sleepy-discord/blob/master/examples/hello/example0.cpp

Perhaps it's because I'm trying to use master as opposed to v0...?

@yourWaifu
Copy link
Owner

Any errors?

@Gazoo101
Copy link
Author

None - there's no output, no nothing. I'm pretty sure it's not actually 'connecting' properly as the bot never appears to even go online in the channel I've invited it to.

@yourWaifu
Copy link
Owner

yourWaifu commented Aug 27, 2021

Can you try debugging and walking through the code and see if run() ever gets called and runs?

@Gazoo101
Copy link
Author

The run command does trigger but appears to end up in default_functions.cpp, where the run() is empty.

@yourWaifu
Copy link
Owner

yourWaifu commented Aug 27, 2021

Looks like the library thinks you are using custom for async and websockets. Can I see your CMakeLists.txt?

@Gazoo101
Copy link
Author

My project unfortunately isn't generated using CMake, as the framework it's based on (libcinder) generates its own Visual Studio solution. It sounds like not having the right flags is causing these issues then.

@yourWaifu
Copy link
Owner

The library is generally configured using CMake, it's how the library knows what library to use for async, websockets, and https.

@Gazoo101
Copy link
Author

I basically build sleepy_discord statically and then manually modify my visual studio properties to include it. Sounds like I need to set the right flags in the externally built project. I've left them unmodified from the defaults they are when checked out.

@yourWaifu
Copy link
Owner

I found this online https://libcinder.org/docs/guides/cmake/cmake.html

@Gazoo101
Copy link
Author

Gazoo101 commented Aug 27, 2021

I appreciate the effort. I think that guide is for building the Cinder framework itself. Not applications built on top of Cinder. Cinder provides a toolkit to generate the visual studio project files for projects built on top of cinder - which is my use case.

In other words, the CMake file I'm missing is not for Cinder, but for the application I have to use Cinder. I think I might know what to do. When I build sleepy-discord externally using CMake, it's provided the USE_WEBSOCKETPP define. But when I then include the statically built lib in my new project (not built in CMake) that flag is now missing leading the headers to assume the existence of custom code, as you point out.

So if I understand things - all I need to do, is to manually add the USE_WEBSOCKETPP define manually to my project.

@yourWaifu
Copy link
Owner

There's more to it than that, There's a number of variables that the library uses that's generated by CMake. Doing this manually isn't something I recommend. I read the article I linked, it says "Building your application with CMake" so it's not just building Cinder but your app with Cinder.

@Gazoo101
Copy link
Author

You're right @yourWaifu . I'll have a look further into it. Really appreciate the prompt and helpful feedback!

@Gazoo101
Copy link
Author

Gazoo101 commented Sep 4, 2021

After about 4 days of work (which I initially estimated to take 1 day - sigh), I managed to fully port my project to build with CMake and eagerly added the linking code for sleepy discord. Unfortunately, I ran into some issues and opted to then reduce the problem down the bare essentials.

My project relies on boost and curl, and thus includes these libraries on its own accord. My current understanding is that some of the definitions in CMake and possibly in the C++ project don't trigger as intended in sleepy discord for me.

I'm wondering if I've neglected to manually set some options in sleepy discord, but so far looking over the code I would think things should work as expected. I can confirm that the Boost_FOUND flag ends up being true.

When the project is finally compiled I run into two errors:

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'boost/asio.hpp': No such file or directory sleepy-discord C:\Code\MiniCMake\deps\sleepy-discord\include\sleepy_discord\asio_include.h 26

and

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'asio/version.hpp': No such file or directory sleepy-discord C:\Code\MiniCMake\deps\sleepy-discord\deps\websocketpp\websocketpp\common\asio.hpp 46

The first one is easy enough to fix, as I reckon I need to add boost to my included folders. The other one I'm far more puzzled about. Despite supposedly using boost for ASIO, the define ASIO_STANDALONE still gets defined somehow.

Am I missing some other settings I need to apply?

Here's my CMake code just in case:

cmake_minimum_required (VERSION 3.6)
project(example)

# For now, we hard-code to build as Win32, just while we're working on
# constantly updating the CMake build process.
set(CMAKE_GENERATOR_PLATFORM Win32)

cmake_path(SET PATH_SDKS "C:/SDKS")

find_package(CURL REQUIRED)

set(BOOST_ROOT "${PATH_SDKS}/boost_1_71_0")
set(BOOST_LIBRARYDIR "${PATH_SDKS}/boost_1_71_0/lib/x86")
set(BOOST_INCLUDEDIR "${PATH_SDKS}/boost_1_71_0/include")

set(Boost_COMPILER "-vc142")
set(Boost_USE_STATIC_LIBS ON)
#set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ON)
#set(Boost_DEBUG ON) # Keep this flag for future debugging
set(Boost_DETAILED_FAILURE_MSG ON)
#set(Boost_ARCHITECTURE "-x64")

find_package(Boost REQUIRED COMPONENTS serialization locale thread system) # system included for asio
set(BOOST_LIBRARIES_TO_INCLUDE Boost::serialization Boost::locale Boost::thread Boost::system)

add_executable(myapp source.cpp)

add_subdirectory(deps/sleepy-discord)
target_link_libraries(myapp sleepy-discord ${BOOST_LIBRARIES_TO_INCLUDE} CURL::libcurl)

@yourWaifu
Copy link
Owner

yourWaifu commented Sep 4, 2021

I like to see the commands that the build tool is running, it should define EXISTENT_BOOST_ASIO

#if defined(SLEEPY_USE_BOOST) || defined(EXISTENT_BOOST_ASIO)
#include <boost/asio.hpp>
#ifndef NONEXISTENT_BOOST_ASIO
#undef NONEXISTENT_ASIO
namespace asio {
using namespace boost::asio;
using boost::system::error_code;
}
#ifdef ASIO_STANDALONE
#undef ASIO_STANDALONE
#endif
#endif
#endif

elseif(USE_BOOST_ASIO)
#Look for boost as an alt
find_package(Boost REQUIRED)
list(APPEND LIBRARIES_TO_LINK ${Boost_LIBRARIES})
list(APPEND LIB_CONFIG "EXISTENT_BOOST_ASIO")

@Gazoo101
Copy link
Author

Gazoo101 commented Sep 4, 2021

Here's the build command that's part of the .slnfile:

/ifcOutput "myapp.dir\Debug\" /GS /analyze- /W3 /Zc:wchar_t /I"C:\Code\MiniCMake\deps\sleepy-discord\include" /I"C:\Code\MiniCMake\deps\sleepy-discord\deps\include" /I"C:\Code\MiniCMake\deps\sleepy-discord\deps\websocketpp" /I"C:\Code\MiniCMake\deps\sleepy-discord\deps\cpr\include" /I"C:\SDKS\vcpkg\installed\x86-windows\include" /I"C:\SDKS\boost_1_71_0\include" /Zi /Gm- /Od /Ob0 /Fd"myapp.dir\Debug\vc142.pdb" /Zc:inline /fp:precise /D "_MBCS" /D "WIN32" /D "_WINDOWS" /D "SLEEPY_DISCORD_CMAKE" /D "EXISTENT_CPR" /D "NONEXISTENT_ASIO" /D "EXISTENT_BOOST_ASIO" /D "EXISTENT_WEBSOCKETPP" /D "NONEXISTENT_UWEBSOCKETS" /D "NONEXISTENT_OPUS" /D "NONEXISTENT_SODIUM" /D "NONEXISTENT_ZLIB_NG" /D "CURL_STATICLIB" /D "CMAKE_INTDIR=\"Debug\"" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /Fa"myapp.dir\Debug\" /EHsc /nologo /Fo"myapp.dir\Debug\" /Fp"myapp.dir\Debug\myapp.pch" /diagnostics:column 

It does define EXISTENT_BOOST_ASIO - However, when building the source, ASIO_STANDALONE also ends up being defined. I think this is a problem because in asio.hpp if ASIO_STANDALONE is defined it tries to include #include <asio/version.hpp> on Line 46. And that file is not available because the project expects to use/rely on boost.

I've tracked ASIO_STANDALONE being defined to websocketpp_common.h which defines ASIO_STANDALONE if BOOST_VERSION is not defined, and it isn't. O_o

I'm still a CMake novice, so I'm not sure if the problem is perhaps that some boost header which is expected to define BOOST_VERSION is missing...?

@Gazoo101
Copy link
Author

Gazoo101 commented Sep 9, 2021

Any thoughts on the issue? I intend to further investigate the matter this weekend myself.

@Gazoo101
Copy link
Author

After further investigation, it appears that some of the defines in sleepy-discord intersect with defines in the framework I use as part of my application. When I figure out exactly where it goes sideways, I'll post something here to help others.

@PhoebeHui
Copy link

Related to microsoft/vcpkg#20372.

@yourWaifu, sleepy-discord supported in vcpkg. Currently it could build on windows, linux and osx.

From https://github.com/yourWaifu/sleepy-discord/blob/develop/CMakeLists.txt#L35. it looks USE_BOOST_ASIO is OFF by default, and enabled when use USE_UWEBSOCKETS and USE_WEBSOCKETPP, however, from https://github.com/yourWaifu/sleepy-discord/blob/develop/sleepy_discord/CMakeLists.txt#L2 adds asio_udp unconditionally.

I want double confirm what's the expected behavior here?

@Gazoo101
Copy link
Author

Gazoo101 commented Oct 1, 2021

My own need for resolution on the issue has ended. It might be worth opening a separate issue for the matter you're inquiring about @PhoebeHui ? I'll keep this open for a few more days, but if there's no follow up I prefer to close it off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants