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

[bug] vcvars not called when using clang-cl #6927

Closed
cqjjjzr opened this issue Apr 29, 2020 · 4 comments · Fixed by #11492
Closed

[bug] vcvars not called when using clang-cl #6927

cqjjjzr opened this issue Apr 29, 2020 · 4 comments · Fixed by #11492
Assignees
Milestone

Comments

@cqjjjzr
Copy link

cqjjjzr commented Apr 29, 2020

Environment Details (include every applicable attribute)

  • Operating System+version: Windows 10 Build 2004
  • Compiler+version: clang 10.0.0 + MSVC Compiler 19.25.28612
  • Conan version: 1.24.1
  • Python version: 3.8.1

Steps to reproduce (Include if Applicable)

Build boost from conan-io/conan-center-index#1453 with line 12 in test_package/conanfile.py changed to:

        with tools.no_op():

Used command with env:

$env:CXX="clang-cl"
$env:CC="clang-cl"
conan create . boost/1.72.0@charliejiang/testing -s compiler=clang -s compiler.version=10 -s compiler.libcxx=libc++ -s build_type=Debug --build missing

Logs (Executed commands with output) (Include/Attach if Applicable)

boost/1.72.0@charliejiang/testing: LIBRARIES: ['libboost_wave', 'libboost_container', 'libboost_contract', 'libboost_exception', 'libboost_graph', 'libboost_iostreams', 'libboost_locale', 'libboost_log', 'libboost_program_options', 'libboost_random', 'libboost_regex', 'libboost_serialization', 'libboost_wserialization', 'libboost_coroutine', 'libboost_fiber', 'libboost_context', 'libboost_timer', 'libboost_thread', 'libboost_chrono', 'libboost_date_time', 'libboost_atomic', 'libboost_filesystem', 'libboost_system', 'libboost_type_erasure', 'libboost_log_setup', 'libboost_math_c99', 'libboost_math_c99f', 'libboost_math_c99l', 'libboost_math_tr1', 'libboost_math_tr1f', 'libboost_math_tr1l', 'libboost_stacktrace_basic', 'libboost_stacktrace_noop', 'libboost_unit_test_framework']
boost/1.72.0@charliejiang/testing: Package folder: C:\.conan\8bbe65\1
boost/1.72.0@charliejiang/testing: Disabled magic autolinking (smart and magic decisions)
boost/1.72.0@charliejiang/testing (test package): Generator cmake created conanbuildinfo.cmake
boost/1.72.0@charliejiang/testing (test package): Generator txt created conanbuildinfo.txt
boost/1.72.0@charliejiang/testing (test package): Generated conaninfo.txt
boost/1.72.0@charliejiang/testing (test package): Generated graphinfo
Using lockfile: 'C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package\build\94d83165358b04cda8851c727a9c78205844de60/conan.lock'
Using cached profile from lockfile
boost/1.72.0@charliejiang/testing (test package): Calling build()
-- The C compiler identification is Clang 10.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 10.0.0 with MSVC-like command-line
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "C:/Program Files/LLVM/bin/clang-cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/cqjjj/source/3rdp/conan-center-index/recipes/boost/all/test_package/build/94d83165358b04cda8851c727a9c78205844de60/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/PROGRA~1/LLVM/bin/mingw32-make.exe cmTC_ba8d9/fast && C:/PROGRA~1/LLVM/bin/mingw32-make.exe -f CMakeFiles\cmTC_ba8d9.dir\build.make CMakeFiles/cmTC_ba8d9.dir/build
    mingw32-make.exe[1]: Entering directory 'C:/Users/cqjjj/source/3rdp/conan-center-index/recipes/boost/all/test_package/build/94d83165358b04cda8851c727a9c78205844de60/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_ba8d9.dir/testCCompiler.c.obj
    C:\PROGRA~1\LLVM\bin\clang-cl.exe  /nologo   /DWIN32 /D_WINDOWS /W3  /MDd /Zi /Ob0 /Od /RTC1   /FoCMakeFiles\cmTC_ba8d9.dir\testCCompiler.c.obj /FdCMakeFiles\cmTC_ba8d9.dir/ -c C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package\build\94d83165358b04cda8851c727a9c78205844de60\CMakeFiles\CMakeTmp\testCCompiler.c
    Linking C executable cmTC_ba8d9.exe
    "C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_ba8d9.dir\link.txt --verbose=1
    "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_ba8d9.dir --rc=C:\PROGRA~1\LLVM\bin\llvm-rc.exe --mt=CMAKE_MT-NOTFOUND --manifests  -- C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo @CMakeFiles\cmTC_ba8d9.dir\objects1.rsp  /out:cmTC_ba8d9.exe /implib:cmTC_ba8d9.lib /pdb:C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package\build\94d83165358b04cda8851c727a9c78205844de60\CMakeFiles\CMakeTmp\cmTC_ba8d9.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
    LINK Pass 1: command "C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo @CMakeFiles\cmTC_ba8d9.dir\objects1.rsp /out:cmTC_ba8d9.exe /implib:cmTC_ba8d9.lib /pdb:C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package\build\94d83165358b04cda8851c727a9c78205844de60\CMakeFiles\CMakeTmp\cmTC_ba8d9.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_ba8d9.dir/intermediate.manifest CMakeFiles\cmTC_ba8d9.dir/manifest.res" failed (exit code 1) with the following output:
    lld-link: error: could not open 'kernel32.lib': no such file or directory
    lld-link: error: could not open 'user32.lib': no such file or directory
    lld-link: error: could not open 'gdi32.lib': no such file or directory
    lld-link: error: could not open 'winspool.lib': no such file or directory
    lld-link: error: could not open 'shell32.lib': no such file or directory
    lld-link: error: could not open 'ole32.lib': no such file or directory
    lld-link: error: could not open 'oleaut32.lib': no such file or directory
    lld-link: error: could not open 'uuid.lib': no such file or directory
    lld-link: error: could not open 'comdlg32.lib': no such file or directory
    lld-link: error: could not open 'advapi32.lib': no such file or directory
    lld-link: error: could not open 'msvcrtd.lib': no such file or directory
    lld-link: error: could not open 'oldnames.lib': no such file or directory
    mingw32-make.exe[1]: *** [CMakeFiles\cmTC_ba8d9.dir\build.make:87: cmTC_ba8d9.exe] Error -1
    mingw32-make.exe[1]: Leaving directory 'C:/Users/cqjjj/source/3rdp/conan-center-index/recipes/boost/all/test_package/build/94d83165358b04cda8851c727a9c78205844de60/CMakeFiles/CMakeTmp'
    mingw32-make.exe: *** [Makefile:120: cmTC_ba8d9/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/Users/cqjjj/source/3rdp/conan-center-index/recipes/boost/all/test_package/build/94d83165358b04cda8851c727a9c78205844de60/CMakeFiles/CMakeOutput.log".
See also "C:/Users/cqjjj/source/3rdp/conan-center-index/recipes/boost/all/test_package/build/94d83165358b04cda8851c727a9c78205844de60/CMakeFiles/CMakeError.log".
ERROR: boost/1.72.0@charliejiang/testing (test package): Error in build() method, line 31
        cmake.configure()
        ConanException: Error 1 while executing cd C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package\build\94d83165358b04cda8851c727a9c78205844de60 && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCONAN_IN_LOCAL_CACHE="OFF" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="10" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libc++" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DBoost_USE_STATIC_LIBS="True" -DWITH_RANDOM="TRUE" -DWITH_REGEX="TRUE" -DWITH_TEST="TRUE" -DWITH_COROUTINE="TRUE" -DWITH_CHRONO="TRUE" -DBoost_NO_BOOST_CMAKE="TRUE" -Wno-dev C:\Users\cqjjj\source\3rdp\conan-center-index\recipes\boost\all\test_package

Workaround:

As written in https://github.com/conan-io/conan-center-index/pull/1453/files/1ac629706f94f1de0bf7046bed3d258cc8b7112f#diff-173d76810e789cb3c367b7e249928559 , explicitly call vcvars() when clang-cl is detected.

Additional information

In cmake helper, the vcvar should be added automatically, so the issue may be caused by failure in such code.

@jgsogo
Copy link
Contributor

jgsogo commented Apr 30, 2020

Given the inputs, if the vcvars is not called it is because of the last and condition in:

if ((is_msvc or is_clangcl) and platform.system() == "Windows" and
                self.generator in ["Ninja", "NMake Makefiles", "NMake Makefiles JOM"]):

Reading through the CMake-build helper sources and the cmake_flags I think Conan is detecting the generator as "MinGW Makefiles".

def get_generator(conanfile):

I'm not an expert in the Windows architecture and the different compilers you can use there, so I'm asking for help now: according to CMake documentation (https://cmake.org/cmake/help/v3.6/generator/MinGW%20Makefiles.html), this generator doesn't look like the best one for this situation...

  • which ones would be the proper lines in the command line to compile this package (without Conan)?
  • what is the different between using "standalone" clang, the toolset clang for Visual Studio and MSBuild+clang?

We can add a patch for this issue, but we really need to understand and maybe rewrite some of our Windows-related helpers. I want to remember here, the pending effort to add a msvc compiler (#3573).

@cqjjjzr
Copy link
Author

cqjjjzr commented Apr 30, 2020

Answ

  • To build the boost itself, the "b2" build tool is used. I'm unfamiliar with this tool, but with some minor changes, the boost itself can be built successfully without vcvars enabled. It's the test_package that is failing.
  • Clang on Windows requires a proper Windows SDK pre-installed (MSVC or MinGW). My clang is using my Visual Studio 2019 toolchain to build. Though I'm not familiar of versions of clang on Windows(mainly two version clang.exe and clang-cl.exe? Maybe there's no difference between clang used in a standalone install and one shipped with vs.)

Another workaround

Yeah, it does succeed with the Ninja generator.

$env:CONAN_CMAKE_GENERATOR="Ninja"

However, I don't think it's a good choice to make Ninja the default because not everyone have Ninja installed.

@SSE4
Copy link
Contributor

SSE4 commented Apr 30, 2020

as clang-cl mimics cl.exe (Microsoft C++ compiler), I believe NMake should be the best match generator. MinGW Makefiles isn't the best, as it requires GNU make, and Ninja requires ninja.exe (obviously).

@memsharded
Copy link
Member

This PR #11492, merged for next 1.53 contains a few changes to better support clang in Windows, mainly for the new CMakeToolchain integration, but some minor changes for others too.

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 conan new hello/0.1 -m=cmake_lib|autotools_lib|msbuild_lib|meson_lib, and open a new issue. Many thanks!

@memsharded memsharded added this to the 1.53 milestone Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants