Skip to content

[C++20 Modules] Can't build Client: static functions doesn't work with header units #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Bizzarrus opened this issue Mar 28, 2025 · 1 comment

Comments

@Bizzarrus
Copy link

My project is heavily using C++20 modules. I'm compiling using VS 2022, with the /translateIncludes option enabled (for compability with some other libraries - this option automatically turns every include of a header into an import of a header unity).

However, header units don't work well with static declarations, because a header unit is a translation unit on its own, and static functions are only defined within the same translation unit, so the consumer of the header can't use the functions that were declared as static.

This results in this build error: error C2129: static function 'bool has_callstack(void) noexcept' declared but not defined when I build my project while including Tracy.hpp and using ``TracyAlloc/TracyFree to markup my memory allocations.

The affected functions are (as far as I've found, maybe there are others that I just don't use yet)

  • bool has_callstack()
  • void* Callstack( int32_t depth )
  • void* tracy_malloc( size_t size )
  • void* tracy_malloc_fast( size_t size )
  • void tracy_free( void* ptr )
  • void tracy_free_fast( void* ptr )
  • void* tracy_realloc( void* ptr, size_t size )

removing the static from the declaration (but keeping the inline or constexpr, so the linker can deduplicate the symbols) fixes the issue.

@JohannesBeranek
Copy link

JohannesBeranek commented Apr 19, 2025

Same issue with a simple FrameMarkerStart that reports an error for tracy_free_fast.

Also using modules with VS 2022

Added tracy using vcpkg + cmake

Edit: Seems this is a general bug with MSVC (@Bizzarrus) having issues with "static inline" definitions in header files that are imported into modules. I don't think there's that much the tracy authors could really do without breaking performance of the lib :( I myself am currently looking into switching to clang in hopes it doesn't have the same issues ...

Edit 2: I don't (yet) know enough about this stuff to judge this, but I've found this:
dcleblanc/SafeInt#61
Seems to be about the same issue, and there they see no issue to making the definitions just inline instead of static inline. Maybe the tracy author(s) can have a look at that.

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

No branches or pull requests

2 participants