Fix: Avoid symbol export when building statically with MSVC#1020
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes MSVC symbol export behavior when building Aravis statically by ensuring __declspec(dllexport) is only applied for shared builds, not static ones.
- Adds conditional logic to only apply
ARV_APIexport macros for shared MSVC builds - Sets default library type to shared to preserve existing build behavior
- Improves GCC visibility handling consistency
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Hi, Please don't take offense, but I'd like to know if there is a real human behind this merge request that seems mostly AI generated. For example, there is a mention of a concern about symbol leaking in PR #550, but I did not find anything about that there. |
Hi, no worries at all!. |
I'm not against AI use. It's just that compilation on Windows is not in my area of expertise, and I don't want to blindly accept related changes. A minor issue about the default_options change: is this really needed ? It seems to set a default value which is already the default. |
I wasn't sure about Meson's default for default_library and added it to be explicit, but since it's already shared by default, it's redundant, and it's better to remove it. |
|
Thanks a lot, Leonardo. |
🛠️ Fix: Avoid unnecessary symbol export with static MSVC builds
Summary
This patch ensures that
__declspec(dllexport)is not applied when Aravis is built statically with MSVC. It updates the logic inmeson.buildto conditionally apply theARV_APImacro only for shared builds, improving compatibility and cleanliness of static builds on Windows.🔍 Problem
When building Aravis statically with MSVC (e.g., via vcpkg with x64-windows-static triplet), the current build system still applies
__declspec(dllexport)globally. This leads to:.liband.expfiles next to user executables.This behavior is not aligned with standard MSVC conventions, where symbol export macros are only needed in shared (DLL) builds.
✅ Solution
This patch modifies the logic in
meson.build:Now, when
default_libraryis'static', no__declspec(dllexport)is added — restoring correct static build behavior.Also, this patch explicitly adds:
to the
project()declaration inmeson.build. This ensures that unless otherwise specified, builds will default to shared libraries, preserving existing workflows and expectations.Users who want static builds can still explicitly override this with:
💡 Justification
This change:
.exp/.libfiles when building user executables.ARV_APImacro or ABI.🧠 Historical Context
This aligns with an earlier discussion in PR #550 (2021), where initial MSVC support was proposed. Back then:
ARV_APIwas added to manage symbol visibility.ARV_APIshould be conditional and not clutter headers unnecessarily.🧪 Testing
Confirmed working with:
/MTd).exp/.libartifacts appear at app link time.🔗 Related