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

[question] AutotoolsToolchain uses MSVC flags with clang #17342

Open
1 task done
jijjijj opened this issue Nov 19, 2024 · 5 comments
Open
1 task done

[question] AutotoolsToolchain uses MSVC flags with clang #17342

jijjijj opened this issue Nov 19, 2024 · 5 comments
Assignees

Comments

@jijjijj
Copy link

jijjijj commented Nov 19, 2024

What is your question?

So I have a Win64 build with clang set as a compiler and I try to build mpg123 which uses Autotools to configure itself. The build fails because Autotools receive -MDd flag inside CFLAGS which is not supported by clang/clang++ only by clang-cl (which I don't want to use).

So I went to code of AutotoolsToolchain and I found this
image
Where _get_msvc_runtime_flag() returns the runtime flag appropriate for MS cl.exe or clang-cl but not for clang. And then in cflags() it just returns it without any regard to the actual compiler in use.

At the same time, when choosing flags relevant for mac/apple compilers it does filter the flags out in case the current system isn't appropriate.
image

What's up with that?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@jijjijj jijjijj changed the title [question] AutotoolsToolchain adds MSVC flags to use with clang [question] AutotoolsToolchain uses MSVC flags with clang Nov 19, 2024
@memsharded
Copy link
Member

Hi @jijjijj

Thanks for your question.

Autotools receive -MDd flag inside CFLAGS which is not supported by clang/clang++ only by clang-cl (which I don't want to use).

Could you please clarify which clang are you using in Windows, the msvc-backed clang (irrespective of clang or clang-cl front), or the msys2-backed clang?

In case you haven't read this, this blog post is relevant: https://blog.conan.io/2022/10/13/Different-flavors-Clang-compiler-Windows.html

I think the MD flag should be supported by both clang/clang-cl msvc-backed compilers, as they use the msvc runtime.

@jijjijj
Copy link
Author

jijjijj commented Nov 20, 2024

@memsharded
Thank you for the response.

I use CLang 19.1.3 provided by LLVM. I downloaded it right from their GitHub page. According to the article it should fall under the "MSVC-backed" clangs

image

@memsharded
Copy link
Member

memsharded commented Nov 20, 2024

I am having a look.
These are the lines for clang-cl produced by CMake (for release and Debug respectively):

[1/2] C:\ws\LLVM\clang18\bin\clang-cl.exe  /nologo -TP  
-IC:\Users\conanws\kk\include /DWIN32 /D_WINDOWS /GR /EHsc /O2 /Ob2 /DNDEBUG
-MD -std:c++14
/showIncludes /FoCMakeFiles\mypkg.dir\src\mypkg.cpp.obj /FdCMakeFiles\mypkg.dir\mypkg.pdb 
-c -- C:\Users\conanws\kk\src\mypkg.cpp

[1/2] C:\ws\LLVM\clang18\bin\clang-cl.exe  /nologo -TP 
-IC:\Users\conanws\kk\include /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 
-MDd -std:c++14 
/showIncludes /FoCMakeFiles\mypkg.dir\src\mypkg.cpp.obj /FdCMakeFiles\mypkg.dir\mypkg.pdb
-c -- C:\Users\conanws\kk\src\mypkg.cpp

And with clang:

[1/2] C:\ws\LLVM\clang18\bin\clang++.exe  -IC:/Users/conanws/kk/include -O3 -DNDEBUG 
-D_DLL -D_MT -Xclang --dependent-lib=msvcrt -std=c++14 -MD -MT
CMakeFiles/mypkg.dir/src/mypkg.cpp.obj -MF CMakeFiles\mypkg.dir\src\mypkg.cpp.obj.d 
-o CMakeFiles/mypkg.dir/src/mypkg.cpp.obj -c C:/Users/conanws/kk/src/mypkg.cpp

[1/2] C:\ws\LLVM\clang18\bin\clang++.exe  -IC:/Users/conanws/kk/include -O0 -g -Xclang -gcodeview
-D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=c++14 -MD -MT
CMakeFiles/mypkg.dir/src/mypkg.cpp.obj -MF CMakeFiles\mypkg.dir\src\mypkg.cpp.obj.d 
-o CMakeFiles/mypkg.dir/src/mypkg.cpp.obj -c C:/Users/conanws/kk/src/mypkg.cpp

The -MD and -MT in clang have different meaning https://clang.llvm.org/docs/ClangCommandLineReference.html

@jijjijj
Copy link
Author

jijjijj commented Nov 21, 2024

So, is this a bug in AutotoolsToolchain?

@memsharded
Copy link
Member

Yes, yes, it looks there is a gap, maybe not only in AutotoolsToolchain, but lack of model for clang/clang-cl differences, as the current model is more focused on the binary compatibility than on the compiler frontend input args.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants