libzt
libzt copied to clipboard
Need a way to avoid __declspec on Windows during static build
Here (https://github.com/zerotier/libzt/blob/master/include/ZeroTierSockets.h#L1005), we have the following code:
#if defined(_WIN32) #ifdef ADD_EXPORTS #define ZTS_API __declspec(dllexport) #else #define ZTS_API __declspec(dllimport) #endif #define ZTCALL __cdecl #else #define ZTS_API #define ZTCALL #endif
Which works great on non-Windows builds, and on Windows shared (DLL) build. However, when doing a static Windows build, you want both ZTS_API
and ZTCALL
defined to nothing, and then you're out of luck.
What you want is:
#if defined(_WIN32) #ifndef ZTS_STATIC #ifdef ADD_EXPORTS #define ZTS_API __declspec(dllexport) #else #define ZTS_API __declspec(dllimport) #endif #else #define ZTS_API #endif #define ZTCALL __cdecl #else #define ZTS_API #define ZTCALL #endif
And during building or using a static libzt you'd define ZTS_STATIC
.
Thanks, I'll test this tonight. Btw, I can add this myself or you can make it into a PR and I'll merge it so you can get credit for your contribution (if you care about that sort of thing).
You can go ahead and edit it, I'm not that great with free time currently.
I have to say, your QA for Windows is not great; commits on master are often not even buildable on it without tweaks.
I don't disagree. Windows really only has official support in the form of the NuGet package currently.
For now I updated the Conan recipe to use the latest libzt (after the big breaking update). For sure it works with MSVC, I haven't had the time to try on Mac/Linux but it should work there too.