Skip to content

fix(cmake+msvc): Restore dllimport on extern template declarations (#5200)#5202

Merged
matejk merged 1 commit intopoco-1.15.1from
5200-msvc-ltcg-compile-error
Feb 12, 2026
Merged

fix(cmake+msvc): Restore dllimport on extern template declarations (#5200)#5202
matejk merged 1 commit intopoco-1.15.1from
5200-msvc-ltcg-compile-error

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Feb 11, 2026

Summary

  • Fix MSVC LNK2005 linker errors when consumers build with LTCG (Link-Time Code Generation) enabled, reported in 1.15.0: linker errors with MSVC link-time-code-generation #5200
  • Change #if defined(POCO_OS_FAMILY_WINDOWS) to #if defined(POCO_OS_FAMILY_WINDOWS) && defined(<Component>_EXPORTS) in all extern template declarations (headers) and explicit template instantiations (.cpp files) across Foundation, JSON, and Data/ODBC
  • Enable LTCG (CMAKE_INTERPROCEDURAL_OPTIMIZATION=ON) on the windows-2025-msvc-cmake CI job to catch this class of bug going forward

Root cause

Commit daf19e5 stripped the API macro (e.g. Foundation_API) from extern template class declarations in headers on all Windows builds. This is correct when building the DLL (dllexport is invalid on extern template in MSVC), but wrong when consuming the DLL — the dllimport annotation is needed so the compiler knows the instantiation lives in the DLL. Without it, consumer TUs silently generate local instantiations, which cause LNK2005 duplicate symbol errors under LTCG.

The fix narrows the condition to only strip the macro when <Component>_EXPORTS is defined (i.e. when building the DLL itself).

Test plan

  • macOS build passes (verified locally)
  • Windows shared-library build with LTCG passes (CI windows-2025-msvc-cmake job, now with -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON)
  • All existing test suites pass

Closes #5200

@matejk matejk changed the base branch from main to poco-1.15.1 February 11, 2026 14:18
@dgrunwald
Copy link
Copy Markdown

dgrunwald commented Feb 12, 2026

I confirm this PR solves the linker error I was seeing in #5200.

@matejk matejk merged commit 776a025 into poco-1.15.1 Feb 12, 2026
100 checks passed
@matejk matejk deleted the 5200-msvc-ltcg-compile-error branch February 12, 2026 10:28
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.15.0: linker errors with MSVC link-time-code-generation

2 participants