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

Visual C++ source incompatibility #111

Open
marcstern opened this issue Jun 30, 2020 · 3 comments
Open

Visual C++ source incompatibility #111

marcstern opened this issue Jun 30, 2020 · 3 comments

Comments

@marcstern
Copy link

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
Copy link

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

@marcstern
Copy link
Author

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

I don't see any fix for that problem

@marcstern
Copy link
Author

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)

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

2 participants