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

Clang with MSVC-like cross build for windows bin from ubuntu have configuration confusion #9505

Closed
1 task done
zuowanbushiwo opened this issue Aug 31, 2021 · 4 comments · Fixed by #11492
Closed
1 task done
Milestone

Comments

@zuowanbushiwo
Copy link

zuowanbushiwo commented Aug 31, 2021

Use the following dockerfile to build a cross-compiled windows program image, based on clang + wine + msvc tools:

DockerFile View

FROM nephatrine/nxbuilder:ubuntu
LABEL maintainer="Daniel Wolf "

ENV WINEARCH=win64 WINEDEBUG=fixme-all WINEPREFIX=/home/packager/.wine WINE=/usr/bin/wine64-development WINESERVER=/usr/bin/wineserver-development
RUN echo "====== INSTALL WINDOWS TOOLS ======"
&& sudo dpkg --add-architecture i386
&& sudo sed -i 'sdeb http://archive.ubuntu.com/ubuntu~deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu~g' /etc/apt/sources.list
&& sudo sed -i 's
deb http://security.ubuntu.com/ubuntu~deb [arch=amd64,i386] http://security.ubuntu.com/ubuntu~g' /etc/apt/sources.list
&& export DEBIAN_FRONTEND=noninteractive && sudo apt-get update
&& sudo apt-get -o Dpkg::Options::="--force-confnew" install -y --no-install-recommends
clang
libicu-dev
nsis
osslsigncode
wine32-development wine64-development winetricks wixl
&& export WINEDLLOVERRIDES="mscoree,mshtml="
&& DISPLAY= ${WINE} wineboot --init
&& while pgrep ${WINESERVER} >/dev/null; do sleep 5; done
&& git -C ${HOME} clone --single-branch --depth=1 -b "johnmcpms/signing" https://github.com/microsoft/msix-packaging.git
&& cd ${HOME}/msix-packaging && ./makelinux.sh --pack --validation-parser
&& sudo mkdir /usr/local/lib/x86_64-linux-gnu && sudo cp -nv .vs/lib/.so /usr/local/lib/x86_64-linux-gnu/ && sudo ldconfig
&& sudo cp -nv .vs/bin/makemsix /usr/local/bin/
&& sudo apt-get remove -y
clang
libicu-dev
&& sudo apt-get autoremove -y && sudo apt-get clean
&& cd ${HOME} && rm -rf /tmp/
/var/tmp/* ${HOME}/msix-packaging
ENV WINDOWS_SYSROOT=${WINEPREFIX}/drive_c

ENV LLVM_MAJOR=11
RUN echo "====== INSTALL LLVM TOOLS ======"
&& export DEBIAN_FRONTEND=noninteractive && sudo apt-get update
&& sudo apt-get -o Dpkg::Options::="--force-confnew" install -y --no-install-recommends
clang-${LLVM_MAJOR} clang-format-${LLVM_MAJOR} clang-tidy-${LLVM_MAJOR} clang-tools-${LLVM_MAJOR} cmake
libc++1-${LLVM_MAJOR} libc++abi1-${LLVM_MAJOR} lld-${LLVM_MAJOR} llvm-${LLVM_MAJOR}
&& sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${LLVM_MAJOR} 100
--slave /usr/bin/llvm-addr2line llvm-addr2line /usr/bin/llvm-addr2line-${LLVM_MAJOR}
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-${LLVM_MAJOR}
--slave /usr/bin/llvm-lib llvm-lib /usr/bin/llvm-lib-${LLVM_MAJOR}
--slave /usr/bin/llvm-mt llvm-mt /usr/bin/llvm-mt-${LLVM_MAJOR}
--slave /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-${LLVM_MAJOR}
--slave /usr/bin/llvm-objcopy llvm-objcopy /usr/bin/llvm-objcopy-${LLVM_MAJOR}
--slave /usr/bin/llvm-objdump llvm-objdump /usr/bin/llvm-objdump-${LLVM_MAJOR}
--slave /usr/bin/llvm-ranlib llvm-ranlib /usr/bin/llvm-ranlib-${LLVM_MAJOR}
--slave /usr/bin/llvm-rc llvm-rc /usr/bin/llvm-rc-${LLVM_MAJOR}
--slave /usr/bin/llvm-readelf llvm-readelf /usr/bin/llvm-readelf-${LLVM_MAJOR}
--slave /usr/bin/llvm-strip llvm-strip /usr/bin/llvm-strip-${LLVM_MAJOR}
&& sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_MAJOR} 100
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_MAJOR}
--slave /usr/bin/clang-cl clang-cl /usr/bin/clang-cl-${LLVM_MAJOR}
--slave /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-${LLVM_MAJOR}
--slave /usr/bin/clang-format clang-format /usr/bin/clang-format-${LLVM_MAJOR}
--slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_MAJOR}
&& sudo update-alternatives --install /usr/bin/lld lld /usr/bin/lld-${LLVM_MAJOR} 100
--slave /usr/bin/ld.lld ld.lld /usr/bin/ld.lld-${LLVM_MAJOR}
--slave /usr/bin/ld64.lld ld64.lld /usr/bin/ld64.lld-${LLVM_MAJOR}
--slave /usr/bin/lld-link lld-link /usr/bin/lld-link-${LLVM_MAJOR}
--slave /usr/bin/wasm-ld wasm-ld /usr/bin/wasm-ld-${LLVM_MAJOR}
&& ls /usr/lib/clang/$LLVM_MAJOR
&& sudo apt-get autoremove -y && sudo apt-get clean
&& rm -rf /tmp/* /var/tmp/*

ENV UniversalCRTSdkDir="${WINEPREFIX}/drive_c/Program Files (x86)/Windows Kits/10/"
VSINSTALLDIR="${WINEPREFIX}/drive_c/Program Files (x86)/Microsoft Visual Studio/2019/Community/"
ENV VCINSTALLDIR="${VSINSTALLDIR}VC/"
WindowsSdkDir="${UniversalCRTSdkDir}"
WindowsSdkBinPath="${UniversalCRTSdkDir}bin/"
RUN echo "====== INSTALL MSVC-WINE ======"
&& export DEBIAN_FRONTEND=noninteractive && sudo apt-get update
&& sudo apt-get -o Dpkg::Options::="--force-confnew" install -y --no-install-recommends
msitools
python3-simplejson
&& git -C ${HOME} clone --single-branch --depth=1 https://github.com/mstorsjo/msvc-wine.git
&& mkdir /tmp/msvc-staging && python3 ${HOME}/msvc-wine/vsdownload.py --accept-license --dest /tmp/msvc-staging
Microsoft.Component.VC.Runtime.UCRTSDK
Microsoft.VisualCpp.ASAN.X86
Microsoft.VisualCpp.CRT.Headers
Microsoft.VisualCpp.CRT.Redist.ARM64
Microsoft.VisualCpp.CRT.Redist.Resources
Microsoft.VisualCpp.CRT.Redist.X64
Microsoft.VisualCpp.CRT.Redist.X86
Microsoft.VisualCpp.CRT.Redist.arm64.OneCore.Desktop
Microsoft.VisualCpp.CRT.Redist.x64.OneCore.Desktop
Microsoft.VisualCpp.CRT.Redist.x86.OneCore.Desktop
Microsoft.VisualCpp.CRT.arm64.Desktop
Microsoft.VisualCpp.CRT.arm64.OneCore.Desktop
Microsoft.VisualCpp.CRT.arm64.Store
Microsoft.VisualCpp.CRT.x64.Desktop
Microsoft.VisualCpp.CRT.x64.OneCore.Desktop
Microsoft.VisualCpp.CRT.x64.Store
Microsoft.VisualCpp.CRT.x86.Desktop
Microsoft.VisualCpp.CRT.x86.OneCore.Desktop
Microsoft.VisualCpp.CRT.x86.Store
Microsoft.VisualCpp.PGO.ARM64
Microsoft.VisualCpp.PGO.Headers
Microsoft.VisualCpp.PGO.X64
Microsoft.VisualCpp.PGO.X86
Microsoft.VisualStudio.Component.Windows10SDK
Microsoft.VisualStudio.Component.Windows10SDK.19041
&& mkdir -p "${UniversalCRTSdkDir}" && mv /tmp/msvc-staging/kits/10/* "${UniversalCRTSdkDir}" && rm -rf /tmp/msvc-staging/kits
&& find "${UniversalCRTSdkDir}" -name 'arm' -type d -exec rm -rf {} + && find "${UniversalCRTSdkDir}" -name '.exe' -type f -delete
&& mkdir -p "${VSINSTALLDIR}" && mv /tmp/msvc-staging/
"${VSINSTALLDIR}"
&& find "${VSINSTALLDIR}" -name 'arm' -type d -exec rm -rf {} + && find "${VSINSTALLDIR}" -name '.exe' -type f -delete
&& sudo apt-get remove -y
msitools
python3-simplejson
&& sudo apt-get autoremove -y && sudo apt-get clean
&& cd /tmp && rm -rf /tmp/
/var/tmp/* ${HOME}/msvc-wine

ENV UCRTVersion=10.0.19041.0
VCToolsVersion=14.29.30133
VCRedistVersion=14.29.30133
ENV VCToolsInstallDir="${VCINSTALLDIR}Tools/MSVC/${VCToolsVersion}/"
VCToolsRedistDir="${VCINSTALLDIR}Redist/MSVC/${VCRedistVersion}/"
WindowsSDKLibVersion=${UCRTVersion}/
WindowsSdkVerBinPath="${WindowsSdkDir}bin/${UCRTVersion}/"
WindowsSDKVersion=${UCRTVersion}/
RUN echo "====== SANITY CHECK ======"
&& echo "== WinSDK: " && ls "${WindowsSdkDir}bin" && ls "${WindowsSdkVerBinPath}"
&& echo "== Redist: " && ls "${VCINSTALLDIR}Redist/MSVC" && ls "${VCToolsRedistDir}"
&& echo "== Tools: " && ls "${VCINSTALLDIR}Tools/MSVC" && ls "${VCToolsInstallDir}"
&& find "${WindowsSdkVerBinPath}x64/ucrt" -name '.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/system32/
&& find "${WindowsSdkVerBinPath}x86/ucrt" -name '
.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/syswow64/
&& find "${VCToolsRedistDir}x64" -name '.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/system32/
&& find "${VCToolsRedistDir}x86" -name '
.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/syswow64/
&& find "${VCToolsRedistDir}debug_nonredist/x64" -name '.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/system32/
&& find "${VCToolsRedistDir}debug_nonredist/x86" -name '
.dll' -type f | xargs -I{} cp -nvs {} ${WINEPREFIX}/drive_c/windows/syswow64/

COPY override /
RUN echo "====== TEST TOOLCHAINS ======"
&& export DEBIAN_FRONTEND=noninteractive && sudo apt-get update
&& sudo apt-get -o Dpkg::Options::="--force-confnew" install -y --no-install-recommends llvm-${LLVM_MAJOR}-dev
&& git -C ${HOME} clone --single-branch --depth=1 -b "release/${LLVM_MAJOR}.x" https://github.com/llvm/llvm-project.git
&& sudo cp -nrv ${HOME}/llvm-project/compiler-rt/include/sanitizer /usr/lib/clang/${LLVM_MAJOR}/include/
&& sudo mkdir /usr/lib/clang/${LLVM_MAJOR}/lib/windows
&& git clone --single-branch --depth=1 https://code.nephatrine.net/nephatrine/hello-test.git
&& export WINEPATH=${WINDOWS_TOOLCHAIN}/x86_64-w64-mingw32/bin
&& mkdir /tmp/build-x86_64 && cd /tmp/build-x86_64
&& cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake
-DCOMPILER_RT_DEFAULT_TARGET_TRIPLE="x86_64-pc-windows-msvc" ${HOME}/llvm-project/compiler-rt
&& ninja && sudo cp -nv ./lib/windows/.lib ./lib/windows/.dll /usr/lib/clang/${LLVM_MAJOR}/lib/windows/
&& rm -rf *
&& cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake ${HOME}/hello-test
&& ninja && ${WINE} ./HelloTest.exe
&& export WINEPATH=${WINDOWS_TOOLCHAIN}/i686-w64-mingw32/bin
&& mkdir /tmp/build-i686 && cd /tmp/build-i686
&& cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-i686-msvc.cmake
-DCOMPILER_RT_DEFAULT_TARGET_TRIPLE="i686-pc-windows-msvc" ${HOME}/llvm-project/compiler-rt
&& ninja && sudo cp -nv ./lib/windows/.lib ./lib/windows/.dll /usr/lib/clang/${LLVM_MAJOR}/lib/windows/
&& rm -rf *
&& cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-i686-msvc.cmake ${HOME}/hello-test
&& ninja && ${WINE} ./HelloTest.exe
&& export WINEPATH=${WINDOWS_TOOLCHAIN}/aarch64-w64-mingw32/bin
&& mkdir /tmp/build-aarch64 && cd /tmp/build-aarch64
&& cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-aarch64-msvc.cmake
-DCOMPILER_RT_BUILD_SANITIZERS=OFF -DCOMPILER_RT_BUILD_XRAY=OFF -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE="aarch64-pc-windows-msvc" ${HOME}/llvm-project/compiler-rt
&& ninja && sudo cp -nv ./lib/windows/.lib /usr/lib/clang/${LLVM_MAJOR}/lib/windows/
&& rm -rf *
&& cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-aarch64-msvc.cmake ${HOME}/hello-test
&& ninja && file HelloTest.exe
&& sudo apt-get remove -y llvm-${LLVM_MAJOR}-dev
&& sudo apt-get autoremove -y && sudo apt-get clean
&& cd ${HOME} && rm -rf /tmp/
/var/tmp/* ${HOME}/hello-test ${HOME}/llvm-project

The matching cmake toolchain file

ToolChain Files View

function(build_vfs_overlay winsdk_src)
    set(vfs_dest "${winsdk_src}/vfs_overlay.yaml")
    if(NOT EXISTS "${vfs_dest}")
        unset(include_dirs)
        file(
            GLOB_RECURSE entries
            LIST_DIRECTORIES true
            "${winsdk_src}/*")
        foreach(entry ${entries})
            if(IS_DIRECTORY "${entry}")
                list(APPEND include_dirs "${entry}")
            endif()
        endforeach()
    file(WRITE "${vfs_dest}" "version: 0\ncase-sensitive: false\nroots:\n")

    foreach(include_dir ${include_dirs})
        file(
            GLOB headers
            RELATIVE "${include_dir}"
            "${include_dir}/*.h")
        if(NOT headers)
            continue()
        endif()

        file(APPEND "${vfs_dest}" "  - name: \"${include_dir}\"\n    type: directory\n    contents:\n")
        foreach(header ${headers})
            file(
                APPEND "${vfs_dest}"
                "      - name: \"${header}\"\n        type: file\n        external-contents: \"${include_dir}/${header}\"\n"
            )
        endforeach()
    endforeach()
endif()

set(CMAKE_C_FLAGS_INIT
    "${CMAKE_C_FLAGS_INIT} -Xclang -ivfsoverlay -Xclang \"${vfs_dest}\""
    PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_INIT
    "${CMAKE_CXX_FLAGS_INIT} -Xclang -ivfsoverlay -Xclang \"${vfs_dest}\""
    PARENT_SCOPE)

endfunction()

function(process_library_path winsdk_src)
set(winsdk_dest "${winsdk_src}-lc")
if(NOT EXISTS "${winsdk_dest}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${winsdk_dest}")
file(
GLOB lib_list
RELATIVE "${winsdk_src}"
"${winsdk_src}/*")
foreach(lib_src ${lib_list})
string(TOLOWER "${lib_src}" lib_dest)
if(NOT "${lib_src}" STREQUAL "${lib_dest}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${winsdk_src}/${lib_src}"
"${winsdk_dest}/${lib_dest}")
endif()
endforeach()
endif()

link_directories("${winsdk_src}" "${winsdk_dest}")

endfunction()

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_SYSTEM_VERSION ${UCRTVersion})
set(CMAKE_VS_PLATFORM_NAME x64)
set(CMAKE_SIZEOF_VOID_P 8)

set(triplet "${CMAKE_SYSTEM_PROCESSOR}-pc-windows-msvc")

set(CMAKE_SYSROOT "$ENV{WINDOWS_SYSROOT}")
list(APPEND CMAKE_PREFIX_PATH "$ENV{WINDOWS_TOOLCHAIN}" "/usr/lib/llvm-${LLVM_MAJOR}")

find_program(CMAKE_C_COMPILER NAMES "clang-cl-${LLVM_MAJOR}" clang-cl)
find_program(CMAKE_CXX_COMPILER NAMES "clang-cl-${LLVM_MAJOR}" clang-cl)
find_program(CMAKE_RC_COMPILER NAMES "llvm-rc-${LLVM_MAJOR}" llvm-rc)

find_program(CMAKE_MT NAMES "llvm-mt-${LLVM_MAJOR}" llvm-mt)
find_program(CMAKE_AR NAMES "llvm-lib-${LLVM_MAJOR}" llvm-lib)
find_program(CMAKE_LINKER NAMES "lld-link-${LLVM_MAJOR}" lld-link)

set(CMAKE_LIBRARY_ARCHITECTURE "${CMAKE_VS_PLATFORM_NAME}")
set(CMAKE_C_LIBRARY_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE})
set(CMAKE_CXX_LIBRARY_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE})
set(MSVC_C_ARCHITECTURE_ID "${CMAKE_VS_PLATFORM_NAME}")
set(MSVC_CXX_ARCHITECTURE_ID "${CMAKE_VS_PLATFORM_NAME}")

set(CMAKE_C_COMPILER_TARGET ${triplet})
set(CMAKE_C_FLAGS_INIT "--target=${CMAKE_C_COMPILER_TARGET} -fms-compatibility /arch:AVX")
set(CMAKE_CXX_COMPILER_TARGET ${triplet})
set(CMAKE_CXX_FLAGS_INIT "--target=${CMAKE_CXX_COMPILER_TARGET} -fms-compatibility /arch:AVX")

set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-imsvc")
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc")

set(CMAKE_EXE_LINKER_FLAGS_INIT "/manifest:no /machine:${CMAKE_VS_PLATFORM_NAME}")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "/manifest:no /machine:${CMAKE_VS_PLATFORM_NAME}")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "/manifest:no /machine:${CMAKE_VS_PLATFORM_NAME}")

set(CMAKE_USER_MAKE_RULES_OVERRIDE "/opt/toolchains/MSVCCompileRules.cmake")

include_directories(
SYSTEM "$ENV{VCToolsInstallDir}include" "$ENV{WindowsSdkDir}Include/$ENV{WindowsSDKVersion}ucrt"
"$ENV{WindowsSdkDir}Include/$ENV{WindowsSDKVersion}shared" "$ENV{WindowsSdkDir}Include/$ENV{WindowsSDKVersion}um"
"$ENV{WindowsSdkDir}Include/$ENV{WindowsSDKVersion}cppwinrt")

build_vfs_overlay("$ENV{WindowsSdkDir}Include")
process_library_path("$ENV{VCToolsInstallDir}lib/${CMAKE_VS_PLATFORM_NAME}")
process_library_path("$ENV{WindowsSdkDir}Lib/$ENV{WindowsSDKLibVersion}ucrt/${CMAKE_VS_PLATFORM_NAME}")
process_library_path("$ENV{WindowsSdkDir}Lib/$ENV{WindowsSDKLibVersion}um/${CMAKE_VS_PLATFORM_NAME}")

find_program(CMAKE_CROSSCOMPILING_EMULATOR NAMES $ENV{WINE} wine)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

When I set the profile host as follows:

[settings]
arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.version=14
os=Windows

[build_requires]

[options]

[env]
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake
CONAN_CMAKE_GENERATOR=Ninja

The following error will appear:

-- The C compiler identification is Clang 11.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Check for working C compiler: /usr/bin/clang-cl
-- Check for working C compiler: /usr/bin/clang-cl -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang-cl
-- Check for working CXX compiler: /usr/bin/clang-cl -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
CMake Error at conan-build-cross/conanbuildinfo.cmake:795 (message):
  Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake
  detected 'Clang'
Call Stack (most recent call first):
  conan-build-cross/conanbuildinfo.cmake:366 (conan_check_compiler)
  CMakeLists.txt:8 (conan_basic_setup)


-- Configuring incomplete, errors occurred!
See also "/home/packager/conan_example/test-conan-protobuf/conan-build-cross/CMakeFiles/CMakeOutput.log".
See also "/home/packager/conan_example/test-conan-protobuf/conan-build-cross/CMakeFiles/CMakeError.log".
ERROR: conanfile.py: Error in build() method, line 17
	cmake.configure()
	ConanException: Error 1 while executing cd '/home/packager/conan_example/test-conan-protobuf/conan-build-cross' && cmake -G "Ninja" -DCONAN_LINK_RUNTIME="/MD" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_TOOLCHAIN_FILE="/opt/toolchains/windows-x86_64-msvc.cmake" -DCONAN_IN_LOCAL_CACHE="OFF" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="14" -DCONAN_CXX_FLAGS="/MP4" -DCONAN_C_FLAGS="/MP4" -DCMAKE_INSTALL_PREFIX="/home/packager/conan_example/test-conan-protobuf/conan-build-cross/package" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_PREFIX_PATH="/home/packager/conan_example/test-conan-protobuf/conan-build-cross" -DCMAKE_MODULE_PATH="/home/packager/conan_example/test-conan-protobuf/conan-build-cross" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -Dprotobuf_LITE="False" -Wno-dev '/home/packager/conan_example/test-conan-protobuf'

When I set the profile host compiler to clang, it is as follows:

[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=11
os=Windows

[build_requires]

[options]

[env]
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake
CONAN_CMAKE_GENERATOR=Ninja

The following error will appear:

[16/16] Linking C static library lib/zlibstatic.lib
zlib/1.2.11: Package '5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20' built
zlib/1.2.11: Build folder /home/packager/.conan/data/zlib/1.2.11/_/_/build/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20
zlib/1.2.11: Generated conaninfo.txt
zlib/1.2.11: Generated conanbuildinfo.txt
zlib/1.2.11: Generating the package
zlib/1.2.11: Package folder /home/packager/.conan/data/zlib/1.2.11/_/_/package/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20
zlib/1.2.11: Calling package()
ERROR: zlib/1.2.11: Error in package() method, line 121
	self._rename_libraries()
while calling '_rename_libraries', line 94
	tools.rename(current_lib, os.path.join(lib_path, "libzlib.a"))
	ConanException: rename /home/packager/.conan/data/zlib/1.2.11/_/_/package/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20/lib/libzlibstatic.a to /home/packager/.conan/data/zlib/1.2.11/_/_/package/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20/lib/libzlib.a failed: [Errno 2] No such file or directory: '/home/packager/.conan/data/zlib/1.2.11/_/_/package/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20/lib/libzlibstatic.a' -> '/home/packager/.conan/data/zlib/1.2.11/_/_/package/5ee21cb21e9cb111333dfe59ddd4f8c908b9fd20/lib/libzlib.a'

There is no libzlibstatic.a in the directory, but has zlibstatic.lib 。 I think it is correct build(), but there are some errors in package(), right? Didn't deal with the situation of clang cross compile windows bin ?

@zuowanbushiwo zuowanbushiwo changed the title [bug] Clang with MSVC-like cross build for windows bin from ubuntu have configuration confusion Clang with MSVC-like cross build for windows bin from ubuntu have configuration confusion Aug 31, 2021
@dmn-star
Copy link

When I use conan under windows with clang-cl, my profiles look like this.
...
compiler=Visual Studio
compiler.toolset=ClangCL
...
It's worth a try.

@zuowanbushiwo
Copy link
Author

@dmn-star
Thanks, I just tried it and it still doesn't work。

Profile 1:

[settings]
arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.toolset=ClangCL
compiler.version=14
os=Windows

[build_requires]

[options]

[env]
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake

Error outPut1:

Cross-build from 'Linux:x86_64' to 'Windows:x86_64'
Installing (downloading, building) binaries...
zlib/1.2.11: Already installed!
zlib/1.2.11: WARN: Build folder is dirty, removing it: /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
zlib/1.2.11: Copying sources to build folder
zlib/1.2.11: Building your package in /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
zlib/1.2.11: Generator cmake created conanbuildinfo.cmake
zlib/1.2.11: Aggregating env generators
zlib/1.2.11: Calling build()
CMake Error: Could not create named generator Visual Studio 14 2015 Win64

Generators
* Unix Makefiles               = Generates standard UNIX makefiles.
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
  Ninja                        = Generates build.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.

zlib/1.2.11: 
zlib/1.2.11: ERROR: Package '51d2b21ea56af5f0fc602a4991c617867b490bc6' build failed
zlib/1.2.11: WARN: Build folder /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
ERROR: zlib/1.2.11: Error in build() method, line 75
	cmake.configure(build_folder=self._build_subfolder)
	ConanException: Error 1 while executing cd '/home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6/build_subfolder' && cmake -G "Visual Studio 14 2015 Win64" -DCONAN_LINK_RUNTIME="/MD" -DCMAKE_TOOLCHAIN_FILE="/opt/toolchains/windows-x86_64-msvc.cmake" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="Visual Studio" -DCONAN_COMPILER_VERSION="14" -DCONAN_CXX_FLAGS="/MP4" -DCONAN_C_FLAGS="/MP4" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="/home/packager/.conan/data/zlib/1.2.11/_/_/package/51d2b21ea56af5f0fc602a4991c617867b490bc6" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -Wno-dev -T "ClangCL" '/home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6'

Profile 2:

[settings]
arch=x86_64
build_type=Release
compiler=Visual Studio
compiler.toolset=ClangCL
compiler.version=14
os=Windows

[build_requires]

[options]

[env]
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/toolchains/windows-x86_64-msvc.cmake
CONAN_CMAKE_GENERATOR=Ninja           //ADD HERE  ADD HERE 

error output 2:

Cross-build from 'Linux:x86_64' to 'Windows:x86_64'
Installing (downloading, building) binaries...
zlib/1.2.11: Already installed!
zlib/1.2.11: WARN: Build folder is dirty, removing it: /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
zlib/1.2.11: Copying sources to build folder
zlib/1.2.11: Building your package in /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
zlib/1.2.11: Generator cmake created conanbuildinfo.cmake
zlib/1.2.11: Aggregating env generators
zlib/1.2.11: Calling build()
zlib/1.2.11: 
zlib/1.2.11: ERROR: Package '51d2b21ea56af5f0fc602a4991c617867b490bc6' build failed
zlib/1.2.11: WARN: Build folder /home/packager/.conan/data/zlib/1.2.11/_/_/build/51d2b21ea56af5f0fc602a4991c617867b490bc6
ERROR: zlib/1.2.11: Error in build() method, line 75
	cmake.configure(build_folder=self._build_subfolder)
	ConanException: CMake does not support toolsets with generator "Ninja:.Please check your conan profile to either remove the toolset, or change the CMake generator.

@dmn-star
Copy link

dmn-star commented Aug 31, 2021

Profile 1
Probably because you called linux cmake. But windows cmake will also not work, because you don't have VS installed.

CMake queries the VS Installer tool through a COM interface to get a list of VS installations. If none is found then we report a brief error:

Generator

Visual Studio 16 2019

 could not find any instance of Visual Studio.

https://gitlab.kitware.com/cmake/cmake/-/issues/22082

@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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants