-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
Clang: fix target triple for MinGW #5980
Conversation
@Doekin I thought the correct target triple is I use LLVM MinGW and these are what I build with --target= |
Hi, @ifarbod, Thank you for raising this point! The reason I opted for
This also aligns with Clang's naming conventions, such as I’d love to hear your thoughts and see if there’s any perspective or use case I might have missed. |
@Doekin This makes sense to me, but maybe we should future-proof this in case Clang decides to change it later, I've never seen anyone specify Also another thing to note here:
Offtopic: Regarding Clang, and compiling for Windows, have you tried to compile on Windows host+target ( |
|
I didn’t know that—appreciate you sharing it! I tried compiling with Clang: Source → Binary
Clang: Source → Object, link.exe : Object → Binary
|
clang always uses msvc link on windows plat unless set_toolchains("clang")
add_cxflags("-v")
add_ldflags("-v")
-- add_ldflags("-fuse-ld=lld-link")
target("test")
set_kind("binary")
add_files("src/main.cpp") [ 50%]: cache compiling.release src\main.cpp
clang -c -Qunused-arguments -m64 --target=x86_64-pc-windows-msvc -fexceptions -fcxx-exceptions -v -o build\.objs\test\windows\x64\release\src\main.cpp.obj src\main.cpp
clang version 19.1.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\star\scoop\apps\llvm\19.1.4\bin
(in-process)
"C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.42.34435 -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic "-fdebug-compilation-dir=A:\\project\\xmake\\test" -v "-fcoverage-compilation-dir=A:\\project\\xmake\\test" -resource-dir "C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\lib\\clang\\19" -dependency-file "C:\\Users\\star\\AppData\\Local\\Temp\\.xmake\\241220\\_7DDA23B0A2F248008DD91ECF943CB360" -MT "build\\.objs\\test\\windows\\x64\\release\\src\\__cpp_main.cpp.cpp" -internal-isystem "C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\lib\\clang\\19\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\cppwinrt" -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.42.34435 -std=c++14 -fskip-odr-check-in-gmf -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -fansi-escape-codes -faddrsig -o "build\\.objs\\test\\windows\\x64\\release\\src\\__cpp_main.cpp.cpp" -x c++ "src\\main.cpp"
clang -cc1 version 19.1.4 based upon LLVM 19.1.4 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
C:\Users\star\scoop\apps\llvm\19.1.4\lib\clang\19\include
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\atlmfc\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt
[ 75%]: linking.release test.exe
clang++ -o build\windows\x64\release\test.exe build\.objs\test\windows\x64\release\src\main.cpp.obj -m64 --target=x86_64-pc-windows-msvc -v
clang version 19.1.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\star\scoop\apps\llvm\19.1.4\bin
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\bin\\Hostx64\\x64\\link.exe" "-out:build\\windows\\x64\\release\\test.exe" -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\um\\x64" "-libpath:C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\lib\\clang\\19\\lib\\windows" -nologo "build\\.objs\\test\\windows\\x64\\release\\src\\main.cpp.obj"
[100%]: build ok, spent 0.578s clang++ -o build\windows\x64\release\test.exe build\.objs\test\windows\x64\release\src\main.cpp.obj -m64 --target=x86_64-windows-msvc -fuse-ld=lld-link -v
clang version 19.1.4
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Users\star\scoop\apps\llvm\19.1.4\bin
"C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\bin\\lld-link" "-out:build\\windows\\x64\\release\\test.exe" -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.42.34433\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\um\\x64" "-libpath:C:\\Users\\star\\scoop\\apps\\llvm\\19.1.4\\lib\\clang\\19\\lib\\windows" -nologo "build\\.objs\\test\\windows\\x64\\release\\src\\main.cpp.obj" |
@Doekin Did you invoke link.exe manually or was it done by Xmake? Also, I noticed something, do you think that @star-hengxing Are you sure? It's using clang wrapper to link (in your results), not MSVC link.exe
|
Let me show an example, this is a basic Windows app that is going to be compiled with multiple toolchains: main.cpp: #include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MessageBoxW(nullptr, L"Successful!", L"Message", MB_OK);
return 0;
} xmake.lua: set_project("Windows Demo")
set_xmakever("2.9.7")
set_languages("c17", "cxx20")
add_rules("mode.debug", "mode.releasedbg", "mode.release")
add_rules("plugin.vsxmake.autoupdate")
add_rules("plugin.compile_commands.autoupdate")
set_allowedplats("windows", "mingw")
target("demo-app", function()
set_group("demo")
set_kind("binary")
add_files("src/*.cpp")
if is_plat("windows", "mingw") then
add_rules("win.sdk.application")
end
end) Compiling with MSVC (default)
|
Yes, I ran
From what I’ve seen, Clang internally invokes
This demonstrates that |
@Doekin Yeah from what I've seen, Clang has a wrapper for link.exe, I thought it's impossible to pass arguments to it, until I discovered e.g. add_ldflags("-Wl,-manifest:embed", {force = true}) I just want to see Xmake in a state that it supports all kind of possible combinations for compiling Windows programs (mingw, msvc, clang, bare clang, etc.) - for example, you can't cross compile for armv7 or arm64 with clang-cl on Xmake (it is possible in reality though) Also I remembered that Visual Studio on ARM, and Clang on Windows 11 ARM64 both exist and I'm not sure if Xmake supports compiling on these (CoPilot+ PC) - most of the attention is on macOS ARM64 so Linux and Windows arm support is usually forgotten by most projects. |
That’s impressive. We might need more testing to ensure all these combinations are fully supported. |
this project only supports mingw & windows (clang + msvc stl) platform, you can use it as a reference.
We can open a new issue for discussion. |
I'd like to also help out if possible, let's open new issues and/or discussions. My current issues:
|
fixes #5973