cisco / cjose

C library implementing the Javascript Object Signing and Encryption (JOSE)
MIT License
104 stars 61 forks source link

Visual C++ source incompatibility #111

Open marcstern opened 4 years ago

marcstern commented 4 years ago

In header.h, globals variables are called the following way: extern const char *CJOSE_HDR_ALG;

In Visual C++, there's no way to have that declaration included in a third-party application, even by providing a DEF file. All exported variables have to be declared with extern __declspec(dllimport).

Proposal, compatible with Visual C++ and others:

#ifdef _MSC_VER
# ifdef CJOSE_BUILD
#  define EXTERN extern __declspec(dllexport) 
# else
#  define EXTERN extern __declspec(dllimport) 
# endif
#else
# define EXTERN extern
#endif

EXTERN const char *CJOSE_HDR_ALG;
sergey-chernikov commented 2 years ago

Builds fine for me with VS2019 using this PR: https://github.com/cisco/cjose/pull/119

marcstern commented 2 years ago

Builds fine for me with VS2019 using this PR: #119

I don't see any fix for that problem

marcstern commented 2 years ago

Actually, the problem is more general than Visual C++. We have

#ifdef __cplusplus
extern "C" {
#endif

/** The JWE algorithm header attribute name. */
extern const char *CJOSE_HDR_ALG;

In case cplusplus is defined, we have twice "extern", which poses a problem with some compilers. The second "extern", on each "const ..." line should be enclosed in "#ifndef cplusplus". This way it's compatible with all cases. Btw, Visual C++ handles thisa automatically without having to declare declspec(dllexport)/declspec(dllimport)