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] cross compiling with clang-cl #7868

Closed
1 task done
rea-yseop opened this issue Oct 13, 2020 · 3 comments · Fixed by #11492
Closed
1 task done

[bug] cross compiling with clang-cl #7868

rea-yseop opened this issue Oct 13, 2020 · 3 comments · Fixed by #11492
Milestone

Comments

@rea-yseop
Copy link

rea-yseop commented Oct 13, 2020

Hello, this might be a feature request and not a bug or just me doing it wrong, so sorry if it is.
Anyway, I am trying to build binaries on Linux for Windows using clang-cl.
I saw that it was possible to cross compile here with mingw: https://docs.conan.io/en/latest/systems_cross_building/cross_building.html

I am on ubuntu and I installed clang-cl with sudo apt-get install clang-tools. Also using conan 1.30.1.
Here's my profile (linux_to_win64) so far.

toolchain=/usr/bin/clang-cl-10 # Adjust this path
target_host=clang-cl-10
cc_compiler=clang
cxx_compiler=clang

[env]
CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
CC=clang-cl-10
CXX=clang-cl-10

[settings]
# We are cross-building to Windows
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=clang

# Adjust to the gcc version of your MinGW package
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Release


[build_requires]
boost/1.71.0@conan/stable

And the command to install it.

conan install . --profile=linux_to_win64 --build=outdated

which gives me the following error

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=clang
compiler.libcxx=libstdc++11
compiler.version=10
os=Windows
os_build=Windows
[options]
[build_requires]
*: boost/1.71.0@conan/stable
[env]
CC=clang-cl-10
CONAN_CMAKE_FIND_ROOT_PATH=/usr/bin/clang-cl-10 # Adjust this path
CXX=clang-cl-10
boost/1.71.0@conan/stable: Not found in local cache, looking in remotes...
boost/1.71.0@conan/stable: Trying with 'nexus'...
Downloading conanmanifest.txt completed [0.69k]                                          
Downloading conanfile.py completed [39.77k]                                              
boost/1.71.0@conan/stable: Downloaded recipe revision 0
zlib/1.2.11@conan/stable: Not found in local cache, looking in remotes...
zlib/1.2.11@conan/stable: Trying with 'nexus'...
Downloading conanmanifest.txt completed [0.29k]                                          
Downloading conanfile.py completed [8.74k]                                               
Downloading conan_export.tgz completed [0.75k]                                           
Decompressing conan_export.tgz completed [0.00k]                                         
zlib/1.2.11@conan/stable: Downloaded recipe revision 0
bzip2/1.0.8@conan/stable: Not found in local cache, looking in remotes...
bzip2/1.0.8@conan/stable: Trying with 'nexus'...
Downloading conanmanifest.txt completed [0.16k]                                          
Downloading conanfile.py completed [2.14k]                                               
Downloading conan_export.tgz completed [0.75k]                                           
Decompressing conan_export.tgz completed [0.00k]                                         
bzip2/1.0.8@conan/stable: Downloaded recipe revision 0
conanfile.txt: Installing package
Requirements
Packages
Build requirements
    boost/1.71.0@conan/stable from 'nexus' - Downloaded
    bzip2/1.0.8@conan/stable from 'nexus' - Downloaded
    zlib/1.2.11@conan/stable from 'nexus' - Downloaded
Build requirements packages
    boost/1.71.0@conan/stable:bf81f0a0d5edcd13bf6dc746387a35f996dd3646 - Build
    bzip2/1.0.8@conan/stable:78aca1eeb7c2fa61e41fff52cfec4417dcebb81f - Build
    zlib/1.2.11@conan/stable:821b52b1137318c997863f6d49d4ff6842edb435 - Build

Installing (downloading, building) binaries...
Downloading conan_sources.tgz completed [0.79k]                                          
Decompressing conan_sources.tgz completed [0.00k]                                        
bzip2/1.0.8@conan/stable: Configuring sources in /home/rea/.conan/data/bzip2/1.0.8/conan/stable/source
Downloading bzip2-1.0.8.tar.gz completed [791.04k]                                       

bzip2/1.0.8@conan/stable: Copying sources to build folder
bzip2/1.0.8@conan/stable: Building your package in /home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f
bzip2/1.0.8@conan/stable: Generator cmake created conanbuildinfo.cmake
bzip2/1.0.8@conan/stable: Calling build()
-- The C compiler identification is Clang 10.0.0 with MSVC-like command-line
-- Check for working C compiler: /usr/bin/clang-cl-10
-- Check for working C compiler: /usr/bin/clang-cl-10 -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/usr/bin/clang-cl-10"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_7691e/fast && /usr/bin/make -f CMakeFiles/cmTC_7691e.dir/build.make CMakeFiles/cmTC_7691e.dir/build
    make[1]: Entering directory '/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_7691e.dir/testCCompiler.c.obj
    /usr/bin/clang-cl-10  /nologo   /DWIN32 /D_WINDOWS /W3  /MDd /Zi /Ob0 /Od /RTC1   /FoCMakeFiles/cmTC_7691e.dir/testCCompiler.c.obj /FdCMakeFiles/cmTC_7691e.dir/ -c /home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_7691e.exe
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7691e.dir/link.txt --verbose=1
    /usr/bin/cmake -E vs_link_exe --intdir=CMakeFiles/cmTC_7691e.dir --rc=llvm-rc --mt=/usr/bin/mt --manifests  -- /usr/bin/link /nologo @CMakeFiles/cmTC_7691e.dir/objects1.rsp  /out:cmTC_7691e.exe /implib:cmTC_7691e.lib /pdb:/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeTmp/cmTC_7691e.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 
    RC Pass 1: command "llvm-rc /fo CMakeFiles/cmTC_7691e.dir/manifest.res CMakeFiles/cmTC_7691e.dir/manifest.rc" failed (exit code 0) with the following output:
    No such file or directorymake[1]: *** [CMakeFiles/cmTC_7691e.dir/build.make:88: cmTC_7691e.exe] Error 255
    make[1]: Leaving directory '/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_7691e/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 "/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeOutput.log".
See also "/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f/CMakeFiles/CMakeError.log".
bzip2/1.0.8@conan/stable: 
bzip2/1.0.8@conan/stable: ERROR: Package '78aca1eeb7c2fa61e41fff52cfec4417dcebb81f' build failed
bzip2/1.0.8@conan/stable: WARN: Build folder /home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f
ERROR: bzip2/1.0.8@conan/stable: Error in build() method, line 53
        cmake = self._configure_cmake()
while calling '_configure_cmake', line 49
        cmake.configure()
        ConanException: Error 1 while executing cd '/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_SYSTEM_NAME="Windows" -DCONAN_CMAKE_FIND_ROOT_PATH="/usr/bin/clang-cl-10 # Adjust this path" -DCMAKE_SYSROOT="/usr/bin/clang-cl-10 # Adjust this path" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="10" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="/home/rea/.conan/data/bzip2/1.0.8/conan/stable/package/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f" -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" -DBZ2_VERSION_STRING="1.0.8" -DBZ2_VERSION_MAJOR="1" -DBZ2_BUILD_EXE="ON" -Wno-dev '/home/rea/.conan/data/bzip2/1.0.8/conan/stable/build/78aca1eeb7c2fa61e41fff52cfec4417dcebb81f'
@ohanar
Copy link
Contributor

ohanar commented Oct 21, 2020

Clang has a different cross compilation model compared to gcc. Generally speaking, most clang binaries that linux distributions provide, or are provided at llvm.org, can produce binaries for all of the architectures and operating systems clang supports. Because of this, you can't simply point to a binary and expect clang to magically intuit the target/host you want for your binaries, you have to do some configuration.

The conan documentation you reference provides a very gcc oriented notion to cross compiling, and I have no idea if conan has support for clang style cross compilation (I doubt it). This probably fits more as a feature to look at with conan 2.0, when build profile (i.e. the system you are compiling on) will be separated from host profile (i.e. the system your binaries will run on).

@rea-yseop
Copy link
Author

Thanks for the answer.
And yes, i realized that it was really hard to do. Even from Windows, a lot a third-party libraries are confused when the OS is Windows but the compiler is Clang.

@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!

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