cjose icon indicating copy to clipboard operation
cjose copied to clipboard

Visual C++ source incompatibility

Open marcstern opened this issue 4 years ago • 3 comments

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;

marcstern avatar Jun 30 '20 16:06 marcstern

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

sergey-chernikov avatar Nov 17 '21 07:11 sergey-chernikov

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

I don't see any fix for that problem

marcstern avatar Apr 06 '22 09:04 marcstern

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)

marcstern avatar Apr 06 '22 09:04 marcstern