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

[feature] add clang support on windows #9295

Closed
1 task
AndreyMlashkin opened this issue Jul 20, 2021 · 28 comments
Closed
1 task

[feature] add clang support on windows #9295

AndreyMlashkin opened this issue Jul 20, 2021 · 28 comments
Assignees
Labels
Milestone

Comments

@AndreyMlashkin
Copy link

Relates to conan-io/conan-center-index#6414 (comment)

If I try to compile with clang, that is not coming from MSVC, conan still try to use it as a MSVC toolchain

MinGW also does not work for windows.

@memsharded
Copy link
Member

Hi @AndreyMlashkin

We would need a bit more details, please.

We have MinGW tests in our test suite that pass for every commit, on Windows.

Please extract from the conan-center thread the relevant details, and try to provide some minimum reproducible example (can we just try it with a conan new "hello world" recipe? and vision for the user interface of the feature.

Also, these might be 2 different features, don't hesitate to submit 2 separate issues, if they are actually different.

@AndreyMlashkin AndreyMlashkin changed the title [feature] add clang and mingw support on windows [feature] add clang support on windows Jul 20, 2021
@AndreyMlashkin
Copy link
Author

Ok, totally make sense, I will change caption from 'add clang and mingw support on windows' to 'add clang support on windows'

A reproducible example you can find here:
https://github.com/AndreyMlashkin/windows-clang-conan/blob/main/Dockerfile

@AndreyMlashkin
Copy link
Author

Maybe I have just filled a conan profile wrong?
https://github.com/AndreyMlashkin/windows-clang-conan/blob/main/profile

But I have tried different configurations...

@memsharded
Copy link
Member

Well, this could also be that the ConanCenter zlib/1.2.11 recipe could not be prepared to build for clang in Windows. There are many libraries in ConanCenter which build scripts are simply not prepared, or sometimes the recipe itself might hardcode some assumptions about the build systems. This is why I would suggest to use a hello world example, which can be easily generated with conan new hello/0.1 -s.

The "legacy" build system integrations, which are the stable ones, and generated with conan new hello/0.1 -s and the used in ConanCenter are now in maintenance mode only, and we are preparing Conan 2.0. Most of the work and new features is done in the new build-system integrations in https://docs.conan.io/en/latest/reference/conanfile/tools.html.

Maybe a better clang support is not easy to be introduced in the stable build system integrations without breaking, so if possible, it would be great to target directly the new ones, which can be also tested with conan new hello/0.1 -m v2_cmake

@AndreyMlashkin
Copy link
Author

I have re-written test code to use a 'hello' test. It still demonstrate the problem. Please, investigate.

@AndreyMlashkin
Copy link
Author

Here is the log output:

Step 9/10 : RUN conan new hello/0.1 -m v2_cmake
---> Running in a9d93ad8b885
File saved: conanfile.py
File saved: src/CMakeLists.txt
File saved: src/hello.cpp
File saved: src/hello.h
File saved: test_package/CMakeLists.txt
File saved: test_package/conanfile.py
File saved: test_package/example.cpp
Removing intermediate container a9d93ad8b885
---> 2673e2fdec81
Step 10/10 : RUN conan create . --build missing
---> Running in a08b4aee20de
Exporting package recipe
hello/0.1 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
hello/0.1 exports_sources: Copied 1 '.cpp' file: hello.cpp
hello/0.1 exports_sources: Copied 1 '.h' file: hello.h
hello/0.1: A new conanfile.py version was exported
hello/0.1: Folder: C:\Users\ContainerAdministrator.conan\data\hello\0.1__\export
hello/0.1: Exported revision: 433e00605e6b7db954049ae82d12ddec
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=clang
compiler.version=12
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
CC=clang-cl
CONAN_CMAKE_GENERATOR=Ninja
CXX=clang-cl
hello/0.1 (test package): Installing package
Requirements
hello/0.1 from local cache - Cache
Packages
hello/0.1:bd500648356902bb5cb5a6961daa81fc25f3f22c - Build

Installing (downloading, building) binaries...
hello/0.1: Configuring sources in C:\Users\ContainerAdministrator.conan\data\hello\0.1__\source
hello/0.1: Copying sources to build folder
hello/0.1: Building your package in C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\bd500648356902bb5cb5a6961daa81fc25f3f22c
hello/0.1: Generator txt created conanbuildinfo.txt
hello/0.1: Calling generate()
hello/0.1: Calling build()
hello/0.1: CMake command: cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/bd500648356902bb5cb5a6961daa81fc25f3f22c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///package/bd500648356902bb5cb5a6961daa81fc25f3f22c" -DCMAKE_SH="CMAKE_SH-NOTFOUND" "C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\bd500648356902bb5cb5a6961daa81fc25f3f22c\src"
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
hello/0.1:
WARN: Remotes registry file missing, creating default one in C:\Users\ContainerAdministrator.conan\remotes.json
hello/0.1: ERROR: Package 'bd500648356902bb5cb5a6961daa81fc25f3f22c' build failed
hello/0.1: WARN: Build folder C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\bd500648356902bb5cb5a6961daa81fc25f3f22c\build/Debug
ERROR: hello/0.1: Error in build() method, line 39
cmake.configure()
ConanException: Error 1 while executing cmake -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/bd500648356902bb5cb5a6961daa81fc25f3f22c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///package/bd500648356902bb5cb5a6961daa81fc25f3f22c" -DCMAKE_SH="CMAKE_SH-NOTFOUND" "C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\bd500648356902bb5cb5a6961daa81fc25f3f22c\src"

@memsharded
Copy link
Member

I have managed to get it working with LLVM-clang 12:

  • conan new hello/0.1 -m v2_cmake
  • Add generators = "VirtualBuildEnv" to the conanfile.py (this step can also be avoided with command line -c tools.env.virtualenv:auto_use=True option)
  • Use profile "clang":
[settings]
os=Windows
arch=x86_64
build_type=Release
compiler=clang
compiler.version=12

[buildenv]
PATH=+(path)C:/ws/LLVM/LLVM12/bin
CC=clang
CXX=clang
RC=clang

[conf]
tools.cmake.cmaketoolchain:generator=Ninja
  • conan create . -pr=clang

There are a couple of unknowns/unmodeled for this, for example which libstdc++ is using (the MSVC one, and it seems the latest installed one MSVC 16 in my case, but this seems a bit uncontrolled).

Definitely this needs some further testing, UI improvements and documentation, both for "clang" and "clang-cl" styles, and also both in Windows and Linux.

@memsharded memsharded added component: Build Build helpers, build systems.. type: feature labels Jul 20, 2021
@memsharded memsharded added this to the 1.40 milestone Jul 20, 2021
@AndreyMlashkin
Copy link
Author

It is still failing in docker. Could you please try to compile this docker on your side?
https://github.com/AndreyMlashkin/windows-clang-conan

docker build .
Sending build context to Docker daemon 77.82kB
Step 1/13 : FROM mcr.microsoft.com/windows/servercore:1909
---> 14b4902a3f0f
Step 2/13 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue';"]
---> Using cache
---> ffdac7ac0f79
Step 3/13 : RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
---> Using cache
---> e88a535be88e
Step 4/13 : RUN choco install llvm -y
---> Using cache
---> baa8f90d3cb4
Step 5/13 : RUN choco install Ninja -y
---> Using cache
---> 10a328ea8cf5
Step 6/13 : RUN choco install cmake -y --installargs 'ADD_CMAKE_TO_PATH=System'
---> Using cache
---> 16e218895ac4
Step 7/13 : RUN choco install conan -y
---> Using cache
---> 572e81d12a87
Step 8/13 : RUN conan new hello/0.1 -m v2_cmake
---> Using cache
---> 15b820cff902
Step 9/13 : SHELL ["cmd", "/wait", "/S", "/C"]
---> Using cache
---> c690574d335d
Step 10/13 : RUN setx /M PATH "%PATH%;C:\Program Files\LLVM\bin"
---> Using cache
---> 5a9bf7e907db
Step 11/13 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
---> Using cache
---> 45b01e8b6709
Step 12/13 : ADD profile C:\Users\ContainerAdministrator.conan\profiles\default
---> Using cache
---> 80caa7f647bb
Step 13/13 : RUN conan create . hello/0.1@ -m v2_cmake -c tools.env.virtualenv:auto_use=True
---> Running in c2585c0f2e9d
Exporting package recipe
hello/0.1 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
hello/0.1 exports_sources: Copied 1 '.cpp' file: hello.cpp
hello/0.1 exports_sources: Copied 1 '.h' file: hello.h
hello/0.1: A new conanfile.py version was exported
hello/0.1: Folder: C:\Users\ContainerAdministrator.conan\data\hello\0.1__\export
hello/0.1: Exported revision: 433e00605e6b7db954049ae82d12ddec
Configuration:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.version=12
os=Windows
[options]
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:auto_use=True
hello/0.1: Forced build from source
hello/0.1 (test package): Installing package
Requirements
hello/0.1 from local cache - Cache
Packages
hello/0.1:953141255571f930532512aaa0e30f6ab1eec04c - Build

Installing (downloading, building) binaries...
hello/0.1: Configuring sources in C:\Users\ContainerAdministrator.conan\data\hello\0.1__\source
hello/0.1: Copying sources to build folder
hello/0.1: Building your package in C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\953141255571f930532512aaa0e30f6ab1eec04c
hello/0.1: Generator txt created conanbuildinfo.txt
hello/0.1: Calling generate()
hello/0.1: Calling build()
hello/0.1: CMake command: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///package/953141255571f930532512aaa0e30f6ab1eec04c" "C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\953141255571f930532512aaa0e30f6ab1eec04c\src"
Configuring environment variables
Using Conan toolchain through C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake.
-- Conan toolchain: Setting BUILD_SHARED_LIBS= OFF
-- The CXX compiler identification is Clang 12.0.0 with GNU-like command-line
-- Detecting CXX compiler ABI info
Using Conan toolchain through .
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang.exe
Using Conan toolchain through .
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:59 (message):
The C++ compiler

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

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeTmp

Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_38584 && [1/2] Building CXX object CMakeFiles/cmTC_38584.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_38584.exe
FAILED: cmTC_38584.exe
cmd.exe /C "cd . && "C:\Program Files\LLVM\bin\clang.exe" -fuse-ld=lld-link -nostartfiles -nostdlib -m64  -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -m64   -Xlinker /subsystem:console CMakeFiles/cmTC_38584.dir/testCXXCompiler.cxx.obj -o cmTC_38584.exe -Xlinker /implib:cmTC_38584.lib -Xlinker /pdb:cmTC_38584.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
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 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcrt.lib': no such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

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/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeOutput.log".
See also "C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeError.log".
hello/0.1:
WARN: Remotes registry file missing, creating default one in C:\Users\ContainerAdministrator.conan\remotes.json
hello/0.1: ERROR: Package '953141255571f930532512aaa0e30f6ab1eec04c' build failed
hello/0.1: WARN: Build folder C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\953141255571f930532512aaa0e30f6ab1eec04c\build/Release
ERROR: hello/0.1: Error in build() method, line 39
cmake.configure()
ConanException: Error 1 while executing "C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\953141255571f930532512aaa0e30f6ab1eec04c\build/generators\conanbuildenv.bat" && cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1///package/953141255571f930532512aaa0e30f6ab1eec04c" "C:\Users\ContainerAdministrator.conan\data\hello\0.1__\build\953141255571f930532512aaa0e30f6ab1eec04c\src"
The command 'powershell -Command $ErrorActionPreference = 'Stop'; conan create . hello/0.1@ -m v2_cmake -c tools.env.virtualenv:auto_use=True' returned a non-zero code: 1

@AndreyMlashkin
Copy link
Author

@memsharded @jgsogo , I have already samples for MSVC, mingw and clang (the last one does not work yet). Should I commit them to docker tools?
You can use them to dockerize windows CI

@AndreyMlashkin
Copy link
Author

I still have this problem:

Click to expand log
Step 12/13 : RUN conan new hello/0.1 -m v2_cmake
 ---> Running in d33cb2a8cf8a
File saved: conanfile.py
File saved: src/CMakeLists.txt
File saved: src/hello.cpp
File saved: src/hello.h
File saved: test_package/CMakeLists.txt
File saved: test_package/conanfile.py
File saved: test_package/example.cpp
Removing intermediate container d33cb2a8cf8a
 ---> a6e898681eac
Step 13/13 : RUN conan create . hello/0.1@ -m v2_cmake -c tools.env.virtualenv:auto_use=True
 ---> Running in 8211f79d94e1
Exporting package recipe
hello/0.1 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
hello/0.1 exports_sources: Copied 1 '.cpp' file: hello.cpp
hello/0.1 exports_sources: Copied 1 '.h' file: hello.h
hello/0.1: A new conanfile.py version was exported
hello/0.1: Folder: C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\export
hello/0.1: Exported revision: 433e00605e6b7db954049ae82d12ddec
Configuration:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.version=12
os=Windows
[options]
[build_requires]
[env]
CC=clang
CXX=clang++
RC=clang
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:auto_use=True
hello/0.1: Forced build from source
hello/0.1 (test package): Installing package
Requirements
    hello/0.1 from local cache - Cache
Packages
    hello/0.1:953141255571f930532512aaa0e30f6ab1eec04c - Build

Installing (downloading, building) binaries...
hello/0.1: Configuring sources in C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\source
hello/0.1: Copying sources to build folder
hello/0.1: Building your package in C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\build\953141255571f930532512aaa0e30f6ab1eec04c
hello/0.1: Generator txt created conanbuildinfo.txt
hello/0.1: Calling generate()
hello/0.1: Calling build()
hello/0.1: CMake command: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/package/953141255571f930532512aaa0e30f6ab1eec04c" "C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\build\953141255571f930532512aaa0e30f6ab1eec04c\src"
Using Conan toolchain through C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake.
-- Conan toolchain: Setting BUILD_SHARED_LIBS= OFF
-- The CXX compiler identification is Clang 12.0.0 with GNU-like command-line
-- Detecting CXX compiler ABI info
Using Conan toolchain through .
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe
Using Conan toolchain through .
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:59 (message):
  The C++ compiler

    "C:/Program Files/LLVM/bin/clang++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_92723 && [1/2] Building CXX object CMakeFiles/cmTC_92723.dir/testCXXCompiler.cxx.obj
    [2/2] Linking CXX executable cmTC_92723.exe
    FAILED: cmTC_92723.exe
    cmd.exe /C "cd . && "C:\Program Files\LLVM\bin\clang++.exe" -fuse-ld=lld-link -nostartfiles -nostdlib -m64  -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -m64   -Xlinker /subsystem:console CMakeFiles/cmTC_92723.dir/testCXXCompiler.cxx.obj -o cmTC_92723.exe -Xlinker /implib:cmTC_92723.lib -Xlinker /pdb:cmTC_92723.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
    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 'oldnames.lib': no such file or directory
    lld-link: error: could not open 'msvcrt.lib': no such file or directory
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.





  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/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeOutput.log".
See also "C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeError.log".
hello/0.1:
WARN: Remotes registry file missing, creating default one in C:\Users\ContainerAdministrator\.conan\remotes.json
hello/0.1: ERROR: Package '953141255571f930532512aaa0e30f6ab1eec04c' build failed
hello/0.1: WARN: Build folder C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\build\953141255571f930532512aaa0e30f6ab1eec04c\build/Release
ERROR: hello/0.1: Error in build() method, line 39
        cmake.configure()
        ConanException: Error 1 while executing cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/package/953141255571f930532512aaa0e30f6ab1eec04c" "C:\Users\ContainerAdministrator\.conan\data\hello\0.1\_\_\build\953141255571f930532512aaa0e30f6ab1eec04c\src"

@SSE4
Copy link
Contributor

SSE4 commented Aug 9, 2021

it seems like it needs libraries from Windows SDK:

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 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcrt.lib': no such file or directory

have you installed them in your image? I don't think clang redistributes Microsoft libraries.

@SSE4
Copy link
Contributor

SSE4 commented Aug 9, 2021

linking to the #1839

@AndreyMlashkin
Copy link
Author

Thanks for the hint, that brings me a bit further to this error:

Configuring environment variables
Using Conan toolchain through C:/Users/ContainerAdministrator/.conan/data/hello/0.1///build/953141255571f930532512aaa0e30f6ab1eec04c/build/generators/conan_toolchain.cmake.
-- Conan toolchain: Setting BUILD_SHARED_LIBS= OFF
-- The CXX compiler identification is Clang 12.0.0 with GNU-like command-line
-- Detecting CXX compiler ABI info
Using Conan toolchain through .
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang.exe
Using Conan toolchain through .
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:59 (message):
The C++ compiler

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

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/ContainerAdministrator/.conan/data/hello/0.1/_/_/build/953141255571f930532512aaa0e30f6ab1eec04c/build/Release/CMakeFiles/CMakeTmp

Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_a76d1 && [1/2] Building CXX object CMakeFiles/cmTC_a76d1.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_a76d1.exe
FAILED: cmTC_a76d1.exe
cmd.exe /C "cd . && "C:\Program Files\LLVM\bin\clang.exe" -fuse-ld=lld-link -nostartfiles -nostdlib -m64  -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -m64   -Xlinker /subsystem:console CMakeFiles/cmTC_a76d1.dir/testCXXCompiler.cxx.obj -o cmTC_a76d1.exe -Xlinker /implib:cmTC_a76d1.lib -Xlinker /pdb:cmTC_a76d1.pdb -Xlinker /version:0.0   -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: error: could not open 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcrt.lib': no such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

@dmn-star
Copy link

Clang on Windows is not self-sufficient. Why not just use clang-cl, you have to install VS anyway?

@SSE4
Copy link
Contributor

SSE4 commented Aug 11, 2021

lld-link: error: could not open 'oldnames.lib': no such file or directory
lld-link: error: could not open 'msvcrt.lib': no such file or directory

these files are not part of the Windows SDK, they are Visual Studio runtime libraries. I don't know if they could be installed without Visual Studio (or Visual Studio build tools).

@dmn-star
Copy link

dmn-star commented Aug 11, 2021

The import lib for C runtime library (UCRT) is included in Win SDK.

Starting in Visual Studio 2015, the CRT has been refactored into new binaries. The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. The UCRT is now a Windows component, and ships as part of Windows 10. The static library, DLL import library, and header files for the UCRT are now found in the Windows 10 SDK. When you install Visual C++, Visual Studio setup installs the subset of the Windows 10 SDK required to use the UCRT.

https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160

@AndreyMlashkin
Copy link
Author

Clang on Windows is not self-sufficient. Why not just use clang-cl, you have to install VS anyway?

I want to build in Docker and size of an image is very important. Installing minimal Visual Studio takes 5-8GB. It's not acceptable.

@memsharded
Copy link
Member

I am adding tests to our test suite in https://github.com/conan-io/conan/pull/9477/files, so far:

  • CMake + independent Clang + Ninja/Mingw
  • CMake + Visual Studio 16 + Internal VS ClangCL toolset (LLVM 11)

@memsharded
Copy link
Member

Based on the feedback above, at this point seems more an environment setup issue, related to that microsoft tools in that docker image, not a Conan issue?

@AndreyMlashkin
Copy link
Author

A question: does the toolchain
CMake + independent Clang + Ninja/Mingw
require Visual Studio to be installed?

@memsharded
Copy link
Member

CMake + independent Clang + Ninja/Mingw
require Visual Studio to be installed?

Good question, the thing is that the test output is:

    assert "main __clang_major__12" in client.out
    # Check this! Clang compiler in Windows is reporting MSC_VER and MSVC_LANG!
    assert "main _MSC_VER19" in client.out
    assert "main _MSVC_LANG2014" in client.out

So clang in windows itself is reporting some MSVC variables, but I think that it doesn't need VS to be installed at all, though it might need the runtime redistributable to run.

@dmn-star
Copy link

dmn-star commented Aug 27, 2021

The question of only using llvm on Windows comes up regularly. I would say not yet. But actually only you can answer this question for your project. You can try lld linker and see what happens. But you will need Windows SDK in any case.

e.g. here rust-lang/rust#71520

or

https://users.rust-lang.org/t/can-i-compile-on-windows-using-nothing-but-the-llvm-toolchain/25683

@dmn-star
Copy link

The next problem will be that many recipes are not designed for this at all. Search for compiler != "Visual Studio" and you will see that in this case Mingw is assumed. Please check conan-io/conan-center-index#6155 too.

@SSE4
Copy link
Contributor

SSE4 commented Aug 27, 2021

yes, same story about other compilers, e.g. Intel - it also installs on top of Visual Studio and requires it, and it also will fail for checks like compiler != Visual Studio.

@memsharded
Copy link
Member

The next problem will be that many recipes are not designed for this at all. Search for compiler != "Visual Studio" and you will see that in this case Mingw is assumed. Please check conan-io/conan-center-index#6155 too.

yes, same story about other compilers, e.g. Intel - it also installs on top of Visual Studio and requires it, and it also will fail for checks like compiler != Visual Studio.

Sure, this is the reason we are putting some effort into this issue, the idea is to keep adding testing and improving the new build system integrations like CMakeToolchain, so it is not necessary to check those conditionals in recipes directly in many cases. For other cases that is necessary, sure, that would be a recipe issue and can be discussed in the recipe or conancenter repo.

@memsharded
Copy link
Member

#9477 is merging tests that verify that clang is supported on Windows, at least for the 2 most relevant cases (independent clang and MSVC integrated clang), so considering this solved.

Please report detailed failures of the integration, it would be great if possible to use the new tests in the test suite. Thanks!

@mcandre
Copy link

mcandre commented Sep 5, 2021

@memsharded This is exciting news!

Which conan release version will include these changes?

@memsharded
Copy link
Member

@mcandre Conan 1.40 to be released tomorrow contains the ClangCL necessary change in CMakeToolchain, but the independent clang should work with 1.39 too.

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

No branches or pull requests

5 participants