Skip to content

config: use __declspec(dllexport) on all Windows (MinGW/Clang), not just MSVC#231

Merged
jcelerier merged 1 commit into
masterfrom
fix/mingw-pe-dllexport
Jul 12, 2026
Merged

config: use __declspec(dllexport) on all Windows (MinGW/Clang), not just MSVC#231
jcelerier merged 1 commit into
masterfrom
fix/mingw-pe-dllexport

Conversation

@jcelerier

Copy link
Copy Markdown
Member

Problem

LIBREMIDI_EXPORT resolved to __attribute__((visibility("default"))) on the GCC/Clang path:

#if defined(LIBREMIDI_EXPORTS) || defined(LIBREMIDI_MODULE_BUILD)
  #if defined(_MSC_VER)
    #define LIBREMIDI_EXPORT __declspec(dllexport)
  #elif defined(__GNUC__) || defined(__clang__)
    #define LIBREMIDI_EXPORT __attribute__((visibility("default")))
  #endif

But visibility is an ELF concept. On Windows PE/COFF (MinGW-GCC and Clang targeting *-w64-windows-gnu) it is silently inert — it produces no PE export. So on those toolchains:

  • a shared libremidi (.dll) built with MinGW/Clang exports none of its API, and
  • a static libremidi re-exported from an executable (e.g. a host that JIT-compiles plugins referencing libremidi::reader::parse) exports nothing either.

Only the MSVC branch got __declspec(dllexport).

Fix

Key the dllexport branch on _WIN32 so it covers all Windows compilers (MSVC and MinGW/Clang). __declspec(dllexport) is supported by GCC/Clang on mingw and is the correct PE mechanism.

Verification

On x86_64-w64-windows-gnu, compiling:

__attribute__((visibility("default"))) int vis_func() { return 1; }
__declspec(dllexport)                   int dll_func() { return 2; }

llvm-objdump -s --section=.drectve shows a -export: directive only for dll_funcvis_func produces none. Confirmed against the real symptom: a MinGW/Clang-built static libremidi shows 0 -export: directives; after this change its public API (reader, observer, available_apis, …) exports correctly.

This should be validated by the existing MSYS/MinGW CI matrix.

visibility("default") is ELF-only and inert for PE/COFF, so on MinGW/Clang
libremidi exported none of its API. Key the dllexport branch on _WIN32 in both
config.hpp and libremidi-c.h.
@jcelerier jcelerier force-pushed the fix/mingw-pe-dllexport branch from b49db9a to 7ed7792 Compare July 12, 2026 17:38
@jcelerier jcelerier merged commit e349dc3 into master Jul 12, 2026
90 checks passed
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