I'm trying to cross-compile simple "hello world" test program on mac machine targeting Windows.
Configuration
conan 2.1cmake 3.28.3llvm clang 17.0.6All installed usinghomebrew.
When I'm cross-compiling 'manually' it works without errors or warnings. It "only" fails for conan/cmake.
Manual steps that work
# To use brew llvm instead of AppleClang
export LLVM_DIR=/opt/homebrew/opt/llvm
export PATH="$LLVM_DIR/bin:$PATH"
export LDFLAGS="-L$LLVM_DIR/lib"
export CPPFLAGS="-I$LLVM_DIR/include"
export CC=$LLVM_DIR/bin/clang
export CXX=$LLVM_DIR/bin/clang++
# For cross compilation (Windows):
export SDK_DIR=/Users/pawel/SDKs
export MSVC_DIR=$SDK_DIR/MSVC/14.39.33519
export WIN_INC_DIR=$SDK_DIR/Win/10/Include/10.0.22621.0
export WIN_LIB_DIR=$SDK_DIR/Win/10/Lib/10.0.22621.0
# Compile
clang++ \
-I$MSVC_DIR/include \
-L$MSVC_DIR/lib/x64 \
-I$WIN_INC_DIR/ucrt \
-L$WIN_LIB_DIR/ucrt/x64 \
-L$WIN_LIB_DIR/um/x64 \
-fuse-ld=lld-link \
-lmsvcrt \
-lucrt \
-lvcruntime \
-o hello.exe \
-target x86_64-pc-windows-msvc \
-g \
-O0 \
hello.cpp
Failing conan/cmake
I'll provide the content of all relevant files below, but first commands I've used:
# conan using host/build pair:
conan install . \
--output-folder=cmake-build-win-debug \
--profile:host=host-windows-llvm-x64-debug \
--profile:build=build-mac-llvm-x64-debug
# cmake using preset generated by conan (it does exist)
cmake --preset windows-debug
coanfile.py
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps
class PackageConan(ConanFile):
settings = 'os', 'build_type', 'compiler', 'arch'
options = {'target_os': ['Windows', 'Macos']}
def generate(self):
tc = CMakeToolchain(self)
tc.presets_prefix = f'{self.options.target_os}'.lower()
tc.generate()
cmake_deps = CMakeDeps(self)
cmake_deps.generate()
CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(hello CXX)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(hello hello.cpp)
Conan profiles
default-llvm
[settings]
arch=armv8
build_type=Release
compiler=clang
compiler.cppstd=20
compiler.libcxx=libc++
compiler.version=17
os=Macos
[buildenv]
CC=/opt/homebrew/opt/llvm/bin/clang
CXX=/opt/homebrew/opt/llvm/bin/clang++
build-mac-llvm-x64-debug
include(default-llvm)
[settings]
arch=x86_64
build_type=Debug
[buildenv]
CXXFLAGS=-g -O0
host-windows-llvm-x64-debug
include(default-llvm)
[settings]
os=Windows
arch=x86_64
build_type=Debug
[options]
target_os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
[buildenv]
CXXFLAGS=-g -O0
LDFLAGS=-fuse-ld=lld-link -L/Users/pawel/SDKs/MSVC/14.39.33519/lib/x64 -L/Users/pawel/SDKs/Win/10/Lib/10.0.22621.0/ucrt/x64 -L/Users/pawel/SDKs/Win/10/Lib/10.0.22621.0/um/x64
PATH=/opt/homebrew/opt/llvm/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Error message
clang++: error: invalid linker name in argument '-fuse-ld=lld-link'