-
Notifications
You must be signed in to change notification settings - Fork 981
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
Using conan with clang-cl and CMake on Windows #1839
Comments
I used both "clang.exe" and "clang-cl.exe". first one accepts GCC-style arguments, while seconds MSVC-style arguments. |
You will always mix binaries with clang on windows - for example, clang doesn't reimplement the MSVC runtime, it uses the libraries / DLLs provided by MSVC. Same for the entire Windows SDK, and so on. If you check the list in your link, most of the components are "complete" or "mostly complete". The only difference between Or you used clang with MingW somehow?
That argument also requires passing a value for compiler.libcxx - and neither stdc++11 or libc++ is correct there. While it's possible that we can compile packages with those flags, in reality, clang on windows will use the c++ standard library provided by MSVC (or libcxx, if you built it yourself, but that's even more experimental) (And in my quick experiment, it also tried to build packages with make, which I do not have installed, but I'll see if I can change that somehow) |
nope, didn't use Clang with MinGW. |
While it indeed gets a few more things working, I'm not 100% comfortable adding such "fixes", or "silencers" to my builds scripts - that's the main reason I'm looking for something without such additions. I rechecked why I'm getting errors, based on the zlib-conan project, which has an open issue about clang support on windows, and turns out that I can indeed build it using clang, assuming that I do specify several environment variables before running conan - which probably should be done automatically in the background. So maybe the issue is just that conan's clang support should be smarter on Windows, and provide better default parameters for CMake:
It's possible that the first is only required when using the Ninja generator I haven't tested the others. |
yep, that's not a real fix, just crutch to get build further. |
Thanks @SSE4 for all the feedback yes, @dutow there are a lot of PRs from @SSE4 related to this issue. We are on it. I am leaving this issue open for further discussion, I think it is quite important to first define some |
Very interested in this issue. Right now we are building with clang-cl, as our codebase does not play well with the default MS cl.exe but we need to link into the MSVC runtimes. Has there been any recent work on this? |
The issue I am running into is I want to be able to use clang-cl as my compiler and the MSVC 2017 runtimes. If I setup my conan profile to have the MSVC 2017 info, and set CC/CXX=clang-cl it will fail to build with the checks here: My alternative, is I can setup my conan profile for clang, setting CC/CXX=clang-cl and I will get warnings about invalid command line options that don't apply that are getting injected by conan. (-stdlib=libstdc++ for example). I also get into all sorts of issues when I try to pull in deps that are built with the full MSVC tool set because the conan compiler settings wont match. So far I have been able to manually override and work around this issue by passing things like If anyone has suggestions on how to set this up, I'm totally game to try it. So far it's just been a sea of pain and suffering. |
The other warning we end up with is
When using clang-cl you end up usually using the msvc link.exe. Other bits that could be relevant is that we are running cmake using the ninja generator for these projects. |
@zscgeek this is tricky to handle
|
At least for cmake, they pretty much have assumed you are going to use clang-cl when on windows + MSVC. I was never able to get cmake to output clang.exe style |
that depends on build system for sure. e.g. for boost b2, clang.exe is used, and all arguments are in GCC style |
I will try to add required changes into this PR: #3256 |
I will keep an eye on it! |
In the meantime, how are others dealing with something like this in the existing system? Or is really nobody else mixing in clang-cl + MSVC? I often find myself resorting to killing off settings.compiler from the final hash to make sure things get correctly found in this type of setup. For the packages we control that are internal that becomes the easiest fix. |
Quick question, from my ignorance about this issue. Could be using the From what I have heard from users is that most could be waiting to use the full |
I can now build on Windows using Clang, CMake and Ninja. But it seems that the clang setting expects the usage of a GNU-like cli for the compiler as it requires libcxx setting in settings.yml. This is not valid on Windows as CMake only supports the usage of clang-cl which expects a MSVC style cli which does not use libstd. It worked fine for me by deleting the libcxx setting under settings.yml from clang, as then clang-cl did not complain about unknown command for libstdc++. There should probably be a setting to differentiate clang with gnu cli and clang with msvc cli. Example of clang profile
This only works when settings.yml for clang looks like this:
Where I have removed the libcxx option, as the msvc interface of clang-cl does not use this option and without removing it conan complains that it needs to be set. |
We're also trying to build with Conan, Clang-cl, CMake and Ninja on Windows. This entire thread was very helpful. @trondhe, your post was especially helpful. We were able to work around the issue you described with Conan expecting a Example
Example
The problem we're running into now is that some third-party Conan package recipes that we use haven't accounted for the possibility of |
Re: GNU command line clang. I have a merge request for CMake to support it on windows - after that gets merged, both clang and clang-cl can be real use cases on windows. In the current version, CMake gets a new information variable (CMAKE_lang_COMPILER_FRONTEND_VARIANT) which lets users differentiate between these. (https://gitlab.kitware.com/cmake/cmake/merge_requests/2992) |
related discussion: conan-io/conan-center-index#9807 |
This PR #11492, merged for next 1.53 contains a few changes to better support clang in Windows, mainly for the new There are some other pending issues about the Windows subsystems environment management, we are also trying to improve them in #12178, so if you are using Clang in some subsystem and depend on the environment, you might want to track this PR too. Closing this issue now, but we know that there might still be some gaps, so please try to update to the new integration (this is necessary for 2.0 anyway), and report what might still be failing against this new integration. The best starting point would be the tests in https://github.com/conan-io/conan/blob/develop/conans/test/functional/toolchains/cmake/test_cmake_toolchain_win_clang.py, or using any of the predefined templates |
@memsharded Doesn't appear to work. I put ccache ahead of cl.exe in my path, and set it via my conan profile, but cmake is still is calling the compiler out of the visual studio directory.
I even changed the name of the binary in my conan profile...
I tried specifying a full path to Conan/cmake is still running cl.exe from...
|
Apparently MSBuild automatically overrides the compiler paths.... |
Clang provides the
clang-cl
binary, which is compatible with MSVC'scl
. It can also be used with theNinja
CMake generator, for example, the following way:CMake's internal scripts correctly detect the compiler to be cl-compatible and use the cl style command line parameters in this case.
Conan itself has no knowledge about this compiler, but I assumed that if I compile the dependencies with MSVC (which is the default), I should be able to use them in my CMake project.
While this approach mostly works, the
conanbuildinfo.cmake
script generated by conan detects the compiler as Clang instead of as MSVC, and displays an error, because of the following line:While the Ninja generator sets the compiler id to Clang, it also sets the MSVC variable to 1 and sets the MSVC_VERSION correctly to 1910.
I also know that ideally compilers shouldn't be mixed, but I also assume that adding fully working clang/clang-cl support for conan on windows would be a significant work.
As a simpler solution, this check could be more permissive, for example:
if( (CONAN_COMPILER STREQUAL "Visual Studio" AND NOT MSVC)
MSVC_VERSION
instead of theCMAKE_CXX_COMPILER_VERSION
variable. (currently, this step isn't necessary, because as I described in Missing MSVC version checks in conanbuildinfo.cmake #1838, the MSVC version checks are incomplete and pass even when they shouldn't)This change would allow any compiler which claims to be compatible with the given MSVC version to be used. It would be also consistent with how most projects detect that they are compiled with MSVC.
The text was updated successfully, but these errors were encountered: