Skip to content

fix(win): console tools stay console even when linking GUI-header addons#176

Merged
tettou771 merged 1 commit into
mainfrom
dev
Jul 18, 2026
Merged

fix(win): console tools stay console even when linking GUI-header addons#176
tettou771 merged 1 commit into
mainfrom
dev

Conversation

@tettou771

Copy link
Copy Markdown
Collaborator

Problem

On Windows a TrussC console tool (e.g. anchorbolt) could link as the GUI subsystem instead of console, so it detached from cmd (returned to the prompt immediately), ignored Ctrl+C, and kept running after its console window closed — while still printing nothing to the terminal.

Root cause

TrussC.h emits #pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup") in every TU that includes it (Release, no TRUSSC_SHOW_CONSOLE). In a static-library object (core TrussC, or an addon like tcxWebSocket that includes <TrussC.h>) that directive rides into the final link via the object's .drectve section — and for /subsystem a .drectve directive overrides the command-line /SUBSYSTEM. So one GUI-header-including addon flipped the whole image to GUI, and no command-line flag or local.cmake workaround could win.

Fix

  • Gate the pragma on !defined(TRUSSC_LIBRARY_TU).
  • Define TRUSSC_LIBRARY_TU (PRIVATE) on the core TrussC lib and on every addon target — applied at the _tc_load_addon chokepoint, so it covers both own-CMakeLists.txt addons (via add_subdirectory) and auto addons.

The app's own TUs never get the define, so GUI apps still pin /subsystem:windows from their main TU. The subsystem is now decided solely by the app: GUI by default, console when it defines TRUSSC_SHOW_CONSOLE.

Verification (Windows, MSVC)

Build subsystem
anchorbolt (console tool, links tcxWebSocket) 3 Windows CUI ✅ fixed
a GUI graphics app 2 Windows GUI ✅ no regression

Docs

  • ARCHITECTURE.md §3.5 — new "Windows Subsystem: console tools vs GUI apps".
  • FOR_AI_ASSISTANT.md — console-app creation procedure (define TRUSSC_SHOW_CONSOLE in local.cmake; addons are handled automatically).

Files: core/include/TrussC.h, core/CMakeLists.txt, core/cmake/use_addon.cmake, docs/ARCHITECTURE.md, docs/FOR_AI_ASSISTANT.md.

TrussC.h emits `#pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup")`
in every TU that includes it (Release, no TRUSSC_SHOW_CONSOLE). In a static-
library object (core TrussC or an addon) that directive rides into the final
link via the object's .drectve, and for /subsystem a .drectve overrides the
command-line /SUBSYSTEM — so a single GUI-header-including addon (e.g.
tcxWebSocket) silently turned a console tool into a GUI app that detaches from
its launcher and survives its console window.

Gate the pragma on !defined(TRUSSC_LIBRARY_TU) and define TRUSSC_LIBRARY_TU
(PRIVATE) on the core lib and on every addon target (at the _tc_load_addon
chokepoint, so it covers both own-CMakeLists and auto addons). The app's own
TUs never get the define, so GUI apps still pin /subsystem:windows from their
main TU. The subsystem is now decided solely by the app: GUI by default,
console when it defines TRUSSC_SHOW_CONSOLE.

Verified: anchorbolt links as Console (subsystem 3); a GUI graphics app still
links as Windows (subsystem 2). Documented in ARCHITECTURE.md §3.5 and
FOR_AI_ASSISTANT.md (console-app procedure).
@tettou771
tettou771 merged commit bea57b6 into main Jul 18, 2026
9 checks passed
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