Fix MinGW linker subsystem flag generation for Qt applications#7
Conversation
Co-authored-by: waruqi <151335+waruqi@users.noreply.github.com>
| if target:plat() == "mingw" then | ||
| target:add("ldflags", "--subsystem," .. subsystem, { force = true }) | ||
| else | ||
| target:add("ldflags", "-m" .. subsystem, { force = true }) |
There was a problem hiding this comment.
Reverted the ld section changes as requested. Only modified the gcc section. (commit e1c7e71)
| if target:plat() == "mingw" then | ||
| target:add("ldflags", "-Wl,--subsystem," .. subsystem, { force = true }) | ||
| else | ||
| target:add("ldflags", "-Wl,-m" .. subsystem, { force = true }) |
There was a problem hiding this comment.
不用分平台,直接使用 "-m" .. subsystem ,不要加 -Wl,
There was a problem hiding this comment.
Changed to use -m + subsystem directly without -Wl, wrapper and removed platform detection as suggested. (commit e1c7e71)
There was a problem hiding this comment.
Pull Request Overview
This PR fixes MinGW linker subsystem flag generation for Qt applications by addressing incorrect flag format that caused compilation failures. The issue was that xmake was passing -Wl,-mwindows to MinGW's ld.exe, which interprets -mwindows as an emulation mode rather than a subsystem flag.
- Adds MinGW platform detection to generate correct
--subsystem,windowsflags instead of-mwindows - Maintains backward compatibility with all other platforms
- Fixes compilation errors for Qt widget applications on MinGW
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| target:add("ldflags", "-m" .. subsystem, { force = true }) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
This closing end statement appears to be unmatched. The function structure shows this end doesn't correspond to any opening statement in the visible diff, which will cause a syntax error.
@copilot |
…ctly Co-authored-by: waruqi <151335+waruqi@users.noreply.github.com>
|
Applied the feedback - simplified to use |
The Windows subsystem rule was generating incorrect linker flags for MinGW, causing Qt widget applications to fail compilation with:
The issue occurred because xmake was passing
-Wl,-mwindowsto MinGW's ld.exe, which interprets-mwindowsas an emulation mode (similar to-mi386pep) rather than a subsystem flag. The solution is to pass-mwindowsdirectly without the-Wl,wrapper.Changes Made
Modified
/xmake/rules/platform/windows/subsystem/xmake.luato use the correct flag format:Example
For a Qt widget application like:
Before (broken):
After (working):
This simple change removes the
-Wl,wrapper that was causing the emulation mode confusion while maintaining full backward compatibility with all platforms.Fixes #6.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.