Skip to content

fix: remove redundant lantern.h include causing macro redefinition warning#1430

Merged
dfalbel merged 2 commits intomainfrom
macro-redefinition
Apr 8, 2026
Merged

fix: remove redundant lantern.h include causing macro redefinition warning#1430
dfalbel merged 2 commits intomainfrom
macro-redefinition

Conversation

@dfalbel
Copy link
Copy Markdown
Member

@dfalbel dfalbel commented Apr 8, 2026

Summary

  • Removes the redundant #include <lantern/lantern.h> from device.cpp, which was the only source file with this extra include
  • torch.h already includes lantern/lantern.h with the correct LANTERN_API weak linkage definition; the earlier direct include defined LANTERN_API as empty, then torch.h redefined it as __attribute__((weak)), triggering -Wmacro-redefined

Test plan

  • Verified pkgbuild::compile_dll() compiles device.cpp with no warnings
  • Confirmed the warning was present before the fix and absent after

…n warning

device.cpp was the only source file that directly included lantern/lantern.h
before torch.h. Since torch.h already includes lantern/lantern.h (with the
correct LANTERN_API weak linkage definition), the redundant include caused a
-Wmacro-redefined warning for LANTERN_API.
@dfalbel dfalbel force-pushed the macro-redefinition branch from 64a8afe to e83c37c Compare April 8, 2026 13:18
device.cpp was the only source file that directly included lantern/lantern.h
before torch.h. This caused a -Wmacro-redefined warning because lantern.h
defined LANTERN_API as empty, then torch.h redefined it with weak linkage.

That direct include also happened to provide the lanternInit() function
definition (compiled when LANTERN_HEADERS_ONLY is not set). Move this
responsibility to lantern.cpp where lanternInit() is actually called, and
add #undef LANTERN_API in torch.h so the weak linkage override is clean.
@dfalbel dfalbel merged commit 4e97fc4 into main Apr 8, 2026
7 checks passed
@dfalbel dfalbel deleted the macro-redefinition branch April 8, 2026 17:37
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 participant