OpenSC / pkcs11-helper

Library that simplifies the interaction with PKCS#11 providers for end-user applications using a simple API and optional OpenSSL engine
Other
66 stars 43 forks source link

Cross-compile for Windows broken #48

Closed selvanair closed 2 years ago

selvanair commented 2 years ago

Unfortunately "interface" is defined as "struct" in one of the Windows headers (basetyps.h) which breaks expansion of a macro in pkcs11.h pkcs11.h line 1213:

_CK_DECLARE_FUNCTION (C_GetInterface,
                      (unsigned char *interface_name,
                       struct ck_version *version,
                       struct ck_interface **interface,   <--- gets expanded to struct
                       ck_flags_t flags));

I believe MSVC build also must be affected.

selvanair commented 2 years ago

This can be worked around by adding -DWIN32_LEAN_AND_MEAN during build as that will avoid including some headers which lead to the conflict. A reason why this has not be been reported in OpenSC is probably because they build with that define.

However, its not an solution for users of the library as there are many other ways the conflicting #define could get pulled in an application depending on what Windows features are in use (say, Windows sockets, rpc etc.).

alonbl commented 2 years ago

@selvanair: I've opened https://github.com/OpenSC/OpenSC/pull/2502

However, I do believe that for the last decade or so every windows project must use WIN32_LEAN_AND_MEAN, I am not sure why Microsoft had not made this the default. There is no reason to build projects without it, in OpenVPN when I re-wrote the build system I am sure I've added this as well.

selvanair commented 2 years ago

@alonbl: We do build OpenVPN with WIN32_LEAN_AND_MEAN but we pull in some headers like rpc.h (directly or indirectily) which also defines this offending "interface" keyword. It may be possible to refactor some of that to avoid the conflict, but it looks better to fix it in pkcs11.h.

alonbl commented 2 years ago

I agree, as I wrote I created OpenSC/OpenSC#2502 when this merged I will cherry pick it for this project as well.

alonbl commented 2 years ago

Solved in https://github.com/OpenSC/pkcs11-helper/commit/e18764d5d3ea5ac0550f3aefa6253f36ea24e3a1