we plan on using Clang to compile code for Windows and for Unix. So far we only used Clang to compile code for Windows and therefor used Clang-cl like this:
clang-cl -m64 /O2 /Ot /GS- /MT /nologo -fms-extensions -fms-compatibility -fmsc-version=19 -Wno-ignored-attributes -Wno-writable-strings -Wno-expansion-to-defined /Fo"file.obj" /c “file.cpp”
No problems so far! To cross-compile this code we then extended the command line by:
Which generated the expected output, however, clang-cl does also tell us now:
clang-cl: warning: argument unused during compilation: ‘/O2’ [-Wunused-command-line-argument]
clang-cl: warning: argument unused during compilation: ‘/Ot’ [-Wunused-command-line-argument]
All of a sudden Clang-Cl does not understand those flags anymore, while other flags like /I are still understood. Why is that? And can I (Beginner) fix this?
We use Clang 13.0.0
Thank you for the help in advance c:
I wouldn’t recommend using clang-cl to compile for Unix. It’s really meant for targeting Windows in an MSVC-compatible way. While it may be possible to make it work by passing various flags, that’s really uncharted territory. I would recommend using regular “clang” to target Unix.
The warnings do seem strange. What’s happening is that while most “clang-cl flags” like /MT, /GS- and so on are simple aliases for regular clang flags, the “/O” flags are handled specially, in a class which is only used when targeting Windows (toolchains::MSVCToolChain). Since you’re targeting Unix, that code isn’t run, and the /O flags don’t get handled.
That explanation makes sense to me!
We do have a high interesst in using the MSVC flags, because we are still using the Visual Studio IDE and would like to use it to configurate our projects.
Your concerns do make sense to me, in the end we will most likely introduce our own mapping of the MSVC flags to the Clang ones. I hoped it would be do-able for a beginner to implement that mapping ourself, but I’m not so sure anymore.