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

minbase_decls.h always defines DLL_EXPORT on Windows (issues with static pthread) #305

Open
MajorNr01 opened this issue Dec 26, 2023 · 0 comments

Comments

@MajorNr01
Copy link

I build a static version of GameNetworkingSockets for Windows from source along with its dependencies (Protobuf, OpenSSL), using CMake and MinGW on Linux (cross compile). I configure CMake with -DBUILD_STATIC_LIB=ON -DBUILD_SHARED_LIB=OFF.

When using the built library, I try using the -static argument to statically link standard libraries including libwinpthread.

This causes undefined reference errors for symbols such as __imp_pthread_mutex_lock which I have tracked down to the way the preprocessor evaluates pthread.h. In pthread.h the following preprocessor code:

[...]
#if defined DLL_EXPORT
#ifdef IN_WINPTHREAD
#define WINPTHREAD_API __declspec(dllexport)
#else
#define WINPTHREAD_API __declspec(dllimport)
#endif
#else
#define WINPTHREAD_API
#endif
[...]

causes WINPTHREAD_API to evaluate to __declspec(dllimport) because DLL_EXPORT is defined, meaning that declarations such as

int WINPTHREAD_API pthread_mutex_lock(pthread_mutex_t *m);

evaluate to

int __declspec(dllimport) pthread_mutex_lock(pthread_mutex_t *m);

which creates a reference to the symbol __imp_pthread_mutex_lock. I assume that this is some sort of import function for the actual function but I don't exactly know what's going on here.

There are some indications in different versions of pthread.h (e.g. MSYS2 MinGW64) that this version is not entirely correct and that defining DLL_EXPORT should not result in __declspec(dllimport) declarations.

However, I still believe that GameNetworkingSockets should not define DLL_EXPORT when building a static library. Thus far, my only option for using GameNetworkingSockets and statically linking pthread is to insert #undef DLL_EXPORT at an appropriate location in minbase_decls.h.

Still, if there is something going on here that I don't understand, please tell me about it.

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

1 participant