From 7f72a1eb43158be1c1112d9469421ff0c7ab7ca0 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 8 Sep 2026 19:01:47 +0900 Subject: [PATCH] Match the linkage of rb_digest_wrap_metadata on MSVC digest.h declared it plain while digest.c defines it as RUBY_FUNC_EXPORTED, which cl.exe rejects, so a build with --with-static-linked-ext failed: ext/digest/digest.c(547): error C2375: 'rb_digest_wrap_metadata': redefinition; different linkage Keeping the attribute on the definition is what exports the symbol from libruby when extensions are linked statically. Co-Authored-By: Claude Opus 5 --- ext/digest/digest.c | 3 ++- ext/digest/digest.h | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 28f6022..f0f0910 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -13,6 +13,7 @@ ************************************************/ +#define RB_DIGEST_WRAP_METADATA_LINKAGE RUBY_FUNC_EXPORTED #include "digest.h" static VALUE rb_mDigest; @@ -543,7 +544,7 @@ static const rb_data_type_t metadata_type = { {0}, }; -RUBY_FUNC_EXPORTED VALUE +RB_DIGEST_WRAP_METADATA_LINKAGE VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta) { return rb_obj_freeze(TypedData_Wrap_Struct(0, &metadata_type, (void *)meta)); diff --git a/ext/digest/digest.h b/ext/digest/digest.h index c5c3758..0ad8df6 100644 --- a/ext/digest/digest.h +++ b/ext/digest/digest.h @@ -73,13 +73,21 @@ rb_id_metadata(void) # define DIGEST_USE_RB_EXT_RESOLVE_SYMBOL 1 #endif +/* Declarations and definitions of the same function must carry the same + * attribute on MSVC, and digest.c has to export the definition so that + * statically linked extensions can find the symbol in libruby. */ +#ifndef RB_DIGEST_WRAP_METADATA_LINKAGE +# define RB_DIGEST_WRAP_METADATA_LINKAGE extern +#endif + static inline VALUE rb_digest_make_metadata(const rb_digest_metadata_t *meta) { #if defined(EXTSTATIC) && EXTSTATIC /* The extension is built as a static library, so safe to refer to * rb_digest_wrap_metadata directly. */ - extern VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta); + RB_DIGEST_WRAP_METADATA_LINKAGE + VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta); return rb_digest_wrap_metadata(meta); #else /* The extension is built as a shared library, so we can't refer