cjose
cjose copied to clipboard
Visual C++ source incompatibility
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;
Builds fine for me with VS2019 using this PR: https://github.com/cisco/cjose/pull/119
Builds fine for me with VS2019 using this PR: #119
I don't see any fix for that problem
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)