libzt icon indicating copy to clipboard operation
libzt copied to clipboard

Need a way to avoid __declspec on Windows during static build

Open jbatnozic opened this issue 3 years ago • 4 comments

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.

jbatnozic avatar May 24 '21 18:05 jbatnozic

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).

joseph-henry avatar May 24 '21 22:05 joseph-henry

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.

jbatnozic avatar May 26 '21 13:05 jbatnozic

I don't disagree. Windows really only has official support in the form of the NuGet package currently.

joseph-henry avatar May 26 '21 16:05 joseph-henry

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.

jbatnozic avatar May 26 '21 21:05 jbatnozic