Skip to content

[qtbase] Fix LNK2005 in consumers defining QT_DISABLE_DEPRECATED_BEFORE#50859

Draft
drdanz wants to merge 1 commit intomicrosoft:masterfrom
drdanz:qtcore_static_patch
Draft

[qtbase] Fix LNK2005 in consumers defining QT_DISABLE_DEPRECATED_BEFORE#50859
drdanz wants to merge 1 commit intomicrosoft:masterfrom
drdanz:qtcore_static_patch

Conversation

@drdanz
Copy link
Copy Markdown
Contributor

@drdanz drdanz commented Mar 30, 2026

On Windows static builds, compat/removed_api.cpp emits strong symbol definitions for deprecated APIs. If consumers compile with a higher QT_DISABLE_DEPRECATED_BEFORE value, those same functions become inline definitions in consumer translation units, causing LNK2005 duplicate symbol errors.

Fix this in qtcoreexports.h (generated from cmake/modulecppexports.h.in) by adding a dedicated branch for static consumers that always makes QT_CORE_INLINE_SINCE, QT_CONSTEXPR_INLINE_SINCE and QT_CORE_INLINE_IMPL_SINCE produce non-inline.

  • Changes comply with the maintainer guide.
  • SHA512s are updated for each updated download.
  • The "supports" clause reflects platforms that may be fixed by this new version, or no changes were necessary.
  • Any fixed CI baseline and CI feature baseline entries are removed from that file, or no entries needed to be changed.
  • All patch files in the port are applied and succeed.
  • The version database is fixed by rerunning ./vcpkg x-add-version --all and committing the result.
  • Exactly one version is added in each modified versions file.

@Neumann-A
Copy link
Copy Markdown
Contributor

Link to upstream ticket? Is this fixed in 6.11?

On Windows static builds, compat/removed_api.cpp emits strong symbol
definitions for deprecated APIs. If consumers compile with a higher
QT_DISABLE_DEPRECATED_BEFORE value, those same functions become inline
definitions in consumer translation units, causing LNK2005 duplicate
symbol errors.

Fix this in qtcoreexports.h (generated from cmake/modulecppexports.h.in)
by adding a dedicated branch for static consumers that always makes
QT_CORE_INLINE_SINCE, QT_CONSTEXPR_INLINE_SINCE and
QT_CORE_INLINE_IMPL_SINCE produce non-inline.
@drdanz drdanz force-pushed the qtcore_static_patch branch from b1e34da to 76470fe Compare March 31, 2026 20:05
@drdanz
Copy link
Copy Markdown
Contributor Author

drdanz commented Apr 1, 2026

Link to upstream ticket? Is this fixed in 6.11?

No upstream ticket yet, or at least I haven't found one, and I haven't opened one yet, because I'm still trying to figure out if this is the right fix. I don't think it is fixed in 6.11, but I haven't fully investigated.

@drdanz drdanz marked this pull request as ready for review April 1, 2026 12:46
@drdanz
Copy link
Copy Markdown
Contributor Author

drdanz commented Apr 1, 2026

#50686 rebased over this PR passed all CI checks, therefore this seems to be working properly

@vicroms
Copy link
Copy Markdown
Member

vicroms commented Apr 8, 2026

@drdanz please submit a ticket upstream with these fixes

@vicroms vicroms added the requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look. label Apr 8, 2026
@drdanz
Copy link
Copy Markdown
Contributor Author

drdanz commented Apr 8, 2026

@vicroms
Copy link
Copy Markdown
Member

vicroms commented Apr 8, 2026

We'll wait for the PR to be merged upstream.

@vicroms vicroms marked this pull request as draft April 8, 2026 20:42
@drdanz
Copy link
Copy Markdown
Contributor Author

drdanz commented Apr 9, 2026

Apparently, setting a different QT_DISABLE_DEPRECATED_UP_TO for static builds is not supported in Qt, see the comments on the issue and on the patch, and also https://doc.qt.io/qt-6/qtdeprecationmarkers.html#QT_DISABLE_DEPRECATED_UP_TO

Therefore I'm afraid the patch won't get merged upstream.

This obviously does not work well with vcpkg sharing a single compiled library with all dependencies.

I still believe that the patch is correct, it simply disables building the "disabled" deprecated APIs in the consumer (in static builds only), that are currently compiled because they are inlined.

The function comments clearly say that "static builds treat everything as part of the library, so they never inline" therefore, for static consumers they should never be compiled, and should never be inlined.

The alternative to this patch is probably to patch ECM (and any other dependency that should have the same problem) to not set QT_DISABLE_DEPRECATED_UP_TO for static qt builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires:vcpkg-team-review This PR or issue requires someone on the vcpkg team to take a further look.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants