Skip to content
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

unsupported option '-mwindows' for target 'x86_64-pc-windows-msvc' #69964

Closed
jakirkham opened this issue Oct 23, 2023 · 8 comments
Closed

unsupported option '-mwindows' for target 'x86_64-pc-windows-msvc' #69964

jakirkham opened this issue Oct 23, 2023 · 8 comments
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang-cl platform:windows

Comments

@jakirkham
Copy link

Am seeing the following error when building with Clang 17.0.2 on Windows using MSVC 14.3. AFAICT this is a similar issue as occurred with MinGW ( #64464 ), but this is with MSVC. More background in the OP of PR ( #67891 ) (though that doesn't fix the MSVC target issue)

clang.exe -DHAVE_CONFIG_H -I. -I../../include/private/autogen -I../../include/hwloc/autogen  -I"/d/bld/libhwloc_1696580296225/work"/include -I"/d/bld/libhwloc_1696580296225/work"/include -I../../utils/hwloc  -DLSTOPO_HAVE_GRAPHICS -ID:/bld/libhwloc_1696580296225/_h_env/Library/include -O2 -D_CRT_SECURE_NO_WARNINGS -D_MT -D_DLL -nostdlib -Xclang --dependent-lib=msvcrt -fuse-ld=lld -Dputenv=_putenv -Dmktemp=_mktemp -Dopen=_open -Dunlink=_unlink -Dclose=_close -Dstrdup=_strdup  -mwindows -ID:/bld/libhwloc_1696580296225/_h_env/Library/include -O2 -D_CRT_SECURE_NO_WARNINGS -D_MT -D_DLL -nostdlib -Xclang --dependent-lib=msvcrt -fuse-ld=lld -c -o lstopo_win-lstopo.o `test -f 'lstopo.c' || echo './'`lstopo.c
clang: error: unsupported option '-mwindows' for target 'x86_64-pc-windows-msvc'
@mstorsjo
Copy link
Member

In MSVC mode, the -mwindows flag has never had any effect, and you have probably been getting a warning like clang-16: warning: argument unused during compilation: '-mwindows' [-Wunused-command-line-argument] in older versions.

In conda-forge/libhwloc-feedstock#69 (comment) I see this comment:

However, the problem could be on the libhwloc side, as -mwindows may be a flag that does not make sense for the msvc toolchain of clang, and just by chance this was working on clang <= 16 .

That's exactly the case.

@jakirkham
Copy link
Author

Gotcha. Thanks for your help! 🙏

Will follow up with hwloc then

@jakirkham
Copy link
Author

Raised hwloc issue: open-mpi/hwloc#631

@bgoglin
Copy link

bgoglin commented Oct 23, 2023

(hwloc upstream developer)
GCC -mwindows means "It specifies that a GUI application is to be generated by instructing the linker to set the PE header subsystem type appropriately. "
Is there any way to do that with Clang?

@mstorsjo
Copy link
Member

GCC -mwindows means "It specifies that a GUI application is to be generated by instructing the linker to set the PE header subsystem type appropriately. " Is there any way to do that with Clang?

With Clang in MinGW mode, you can still use -mwindows in that exact same way.

With MSVC, and Clang acting in MSVC mode, you don't normally pass any such flag. It is possible to pass it to the linker (in MSVC mode, most build systems invoke link.exe or lld-link directly without using the compiler driver inbetween) by setting a suitable subsystem parameter, but in most cases, you don't need to, afaik. If no subsystem is specified, it is inferred from the symbols of the linked object files: https://github.com/llvm/llvm-project/blob/llvmorg-17.0.3/lld/COFF/Driver.cpp#L761-L784

@bgoglin
Copy link

bgoglin commented Oct 23, 2023

Hmm, thanks, that's a bit too complicated for my basic knowledge of all these ways to build on windows. I was going to remove -mwindows if building for "x86_64-pc-windows-msvc", but our configure actually see "x86_64-pc-mingw64" instead. It also sees that the compiler is Clang with _MSC_VER defined. Is that a good way to detect this case?

@mstorsjo
Copy link
Member

I was going to remove -mwindows if building for "x86_64-pc-windows-msvc", but our configure actually see "x86_64-pc-mingw64" instead.

I'm not sure what your build environment is - but it seems to be made up from a number of not entirely matched components. You might have some mingw tools somewhere, but the Clang executable you have defaults to MSVC mode.

Primarily, Clang in MSVC mode would be used via the clang-cl interface, which is compatible with the argument style of MSVC's cl.exe. However one can also use Clang in MSVC mode with the GCC-like interface, but that's occasionally confusing.

It also sees that the compiler is Clang with _MSC_VER defined. Is that a good way to detect this case?

Yes, if _MSC_VER is defined, then Clang is operating in MSVC mode.

@Endilll Endilll added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' platform:windows clang-cl and removed new issue labels Oct 26, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 26, 2023

@llvm/issue-subscribers-clang-driver

Author: None (jakirkham)

Am seeing the following error when building with Clang 17.0.2 on Windows using MSVC 14.3. AFAICT this is a similar issue as occurred with MinGW ( https://github.com//issues/64464 ), but this is with MSVC. More background in the OP of PR ( https://github.com//pull/67891 ) (though that doesn't fix the MSVC target issue)
clang.exe -DHAVE_CONFIG_H -I. -I../../include/private/autogen -I../../include/hwloc/autogen  -I"/d/bld/libhwloc_1696580296225/work"/include -I"/d/bld/libhwloc_1696580296225/work"/include -I../../utils/hwloc  -DLSTOPO_HAVE_GRAPHICS -ID:/bld/libhwloc_1696580296225/_h_env/Library/include -O2 -D_CRT_SECURE_NO_WARNINGS -D_MT -D_DLL -nostdlib -Xclang --dependent-lib=msvcrt -fuse-ld=lld -Dputenv=_putenv -Dmktemp=_mktemp -Dopen=_open -Dunlink=_unlink -Dclose=_close -Dstrdup=_strdup  -mwindows -ID:/bld/libhwloc_1696580296225/_h_env/Library/include -O2 -D_CRT_SECURE_NO_WARNINGS -D_MT -D_DLL -nostdlib -Xclang --dependent-lib=msvcrt -fuse-ld=lld -c -o lstopo_win-lstopo.o `test -f 'lstopo.c' || echo './'`lstopo.c
clang: error: unsupported option '-mwindows' for target 'x86_64-pc-windows-msvc'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang-cl platform:windows
Projects
None yet
Development

No branches or pull requests

5 participants