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

Allow JSMN_API to be defined by the user (e. g. for Windows DLLs). #198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lx-s
Copy link

@lx-s lx-s commented Jun 3, 2020

To make jsmn part of a shared Windows-DLL, jsmn's functions have to be marked __declspec(dllexport) / __declscpec(dllimport). Functions marked as extern are - contrary to unix - not automatically exported.

Making JSMN_API user-definable (with a default fallback) makes writing wrapper such as these possible:

jsmn_dll_wrapper.c:

#ifdef _WIN32
#   define JSMN_API __declspec(dllexport)
#endif
#define JSMN_STRICT
#include "jsmn.h"

jsmn_dll_wrapper.h

#ifdef _WIN32
#  ifdef EXPORTS
#     define JSMN_API __declspec(dllexport)
#  else
#     define JSMN_API __declspec(dllimport)
#  endif
#endif
#define JSMN_HEADER
#include "jsmn.h"
#undef JSMN_HEADER

This enables jsmn to be built as part of a Window DLLs, by creating a wrapper header that defines JSMN_HEADER and JSMN_API=__declspec(dllexport).
@lx-s lx-s changed the title Check if JSMN_API has already been defined. Allow JSMN_API to be redefined for Windows DLLs. Jun 29, 2020
@lx-s lx-s changed the title Allow JSMN_API to be redefined for Windows DLLs. Allow JSMN_API to be defined by the user (e. g. for Windows DLLs). Jun 29, 2020
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

Successfully merging this pull request may close these issues.

None yet

1 participant