Skip to content

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

Open
lx-s wants to merge 1 commit into
zserge:masterfrom
lx-s:patch-1
Open

Allow JSMN_API to be defined by the user (e. g. for Windows DLLs).#198
lx-s wants to merge 1 commit into
zserge:masterfrom
lx-s:patch-1

Conversation

@lx-s

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

Copy link
Copy Markdown

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.

1 participant