skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.85k stars 209 forks source link

WIP: shared libs: export classes with functions implemented in .cpp files #197

Closed amurzeau closed 3 years ago

amurzeau commented 4 years ago

When building a DLL on Windows or building a shared library with -fvisibility=hidden on Unix, class with functions implemented in a cpp file must be exported.

This mean __declspec(dllexport) on Windows, and __attribute__((visibility(default))) on Unix.

Changes made:

Currently not working because of static variables in Emitter<>::next_type() and Emitter<>::event_type<>().

Fixes: #196

stefanofiorentino commented 3 years ago

Currently not working because of static variables in Emitter<>::next_type() and Emitter<>::event_type<>().

@amurzeau I have spent some time trying avoiding the monostate pattern causing your testing errors. Just for the readers, this kind of issue arises because with dynamic linking your monostate's statics are two, one in the DLL and one in the executable, so your events don't match any event in the DLL and viceversa. An available solution to this is to move events creation to compile-time (generating a lot of different types of Emitter<>::Handlers). Regrettably this has several drawbacks: majors are the cardinality of the set of different Handlers and the need of the /bigobj flag under MSVC. I think I'll give up on this for a while waiting for more inspiration (i.e. for a better solution). Meanwhile we should use the static linking (imho best linking method anyway).

@skypjack I don't know if you want to close this PR as won't do. Choice is yours.

skypjack commented 3 years ago

I'm implementing yet another approach that makes the event identification somewhat portable across boundaries. I've not much bandwidth, so it may take a while, but still. We can close the PR, we've an issue anyway so as not to forget to work on this. 😉