# CMAKE\_LINKER\_TYPE when cross-compiling not passing correct options

**URL:** https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985
**Category:** Usage
**Tags:** os:linux
**Created:** [November 18, 2024, 6:03pm UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985 "2024-11-18T18:03:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![palmerc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/palmerc/32/5132_2.png) [@palmerc](https://discourse.cmake.org/u/palmerc)
#### Post date: [November 18, 2024, 6:03pm UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/1 "2024-11-18T18:03:31Z")

</div>

Cross-compiling for CMAKE\_SYSTEM\_NAME Darwin using CMAKE\_LINKER\_TYPE LLD does not provide valid command-line options to the linker. Is this expected?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 18, 2024, 8:06pm UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/2 "2024-11-18T20:06:48Z")

</div>

Can you specify your environment (platform, CMake version, compiler, CMake command line)?

---

<div class="post-metadata">

### Author: ![palmerc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/palmerc/32/5132_2.png) [@palmerc](https://discourse.cmake.org/u/palmerc)
#### Post date: [November 18, 2024, 9:11pm UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/3 "2024-11-18T21:11:00Z")

</div>

Platform Ubuntu 22.04, CMake 3.30, LLVM 18.1.8

```auto
CMake toolchain:
set( CMAKE_SYSTEM_NAME Darwin )
set( CMAKE_SYSTEM_VERSION 11.0 )
set( CMAKE_OSX_ARCHITECTURES arm64 )
set( CMAKE_OSX_SYSROOT /opt/apple/sdks/Xcode15.4/MacOSX.platform/Developer/SDKs/MacOSX.sdk )
set( CMAKE_C_COMPILER /opt/llvm/18.1.8/release/bin/clang )
set( CMAKE_CXX_COMPILER /opt/llvm/18.1.8/release/bin/clang++ )
set( CMAKE_ASM_COMPILER /opt/llvm/18.1.8/release/bin/clang )
set( CMAKE_LIBTOOL /opt/llvm/18.1.8/release/bin/llvm-libtool-darwin )
set( CMAKE_LINKER_TYPE LLD )

```

```auto
cmake -G Ninja
-D CMAKE_BUILD_TYPE=Release 
-D CMAKE_INSTALL_PREFIX=/build/dist/build.llvm.macosx.arm.release 
-D CMAKE_VERBOSE_MAKEFILE=on 
-D CMAKE_TOOLCHAIN_FILE=/build/builddir/macosx/toolchain.cmake 
-D LLVM_HOST_TRIPLE=arm64-apple-darwin 
-D CMAKE_SYSTEM_IGNORE_PREFIX_PATH=/Library/Developer/CommandLineTools;/Applications/Xcode.app 
-D LLVM_ENABLE_TERMINFO=off 
-D TERMINFO_LIB=-lcurses 
-D LLVM_ENABLE_FFI=on 
-D LLVM_TARGETS_TO_BUILD=X86;ARM;AArch64 
-D LLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind 
-D LLVM_ENABLE_LIBCXX=on 
-D BUILD_SHARED_LIBS=off 
-D LLVM_ENABLE_PIC=off 
-D LLVM_ENABLE_EH=off 
-D LLVM_ENABLE_RTTI=off
-D LLVM_ENABLE_Z3_SOLVER=off 
-D LLVM_INSTALL_CCTOOLS_SYMLINKS=on 
-D LLVM_BUILD_EXTERNAL_COMPILER_RT=on 
-D LLVM_BUILD_TESTS=off 
-D LLVM_BUILD_TOOLS=on
-D LLVM_INSTALL_UTILS=on 
-D LLVM_OPTIMIZED_TABLEGEN=on 
-D LLVM_INCLUDE_DOCS=off 
-D LLVM_ENABLE_DOXYGEN=off 
-D LLVM_INCLUDE_EXAMPLES=off 
-D LLVM_INCLUDE_TESTS=off 
-D LLVM_ENABLE_PROJECTS=clang;lld
-D CLANG_INCLUDE_TESTS=off 
-D LLVM_ENABLE_LLD=on /build/llvm
../path/to/src

```

---

<div class="post-metadata">

### Author: ![palmerc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/palmerc/32/5132_2.png) [@palmerc](https://discourse.cmake.org/u/palmerc)
#### Post date: [November 19, 2024, 7:17am UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/4 "2024-11-19T07:17:56Z")

</div>

My current thinking is that specifying LLD has some consequences that I need to dig into, namely, that TryCompile vs. cross-compile need two different flavors of LLD, ld64.lld (macOS) and ld.lld (linux) and either I’m specifying this fact incorrectly or cmake doesn’t support this.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 19, 2024, 10:05am UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/5 "2024-11-19T10:05:45Z")

</div>

I don’t think `TryCompile` needs a different linker than the cross-compile one. `TryCompile` is used to check usability of the cross-compiler, so the target linker must be used, not the host one.

Moreover, specifying `CMAKE_LINKER_TYPE` result in the option `-fuse-ld=lld` passed to the cross-compiler which, in turn, will select the linker.

Did-you check that using directly the cross-compiler with option `-fuse-ld=lld` is OK?

---

<div class="post-metadata">

### Author: ![palmerc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/palmerc/32/5132_2.png) [@palmerc](https://discourse.cmake.org/u/palmerc)
#### Post date: [November 19, 2024, 10:29am UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/6 "2024-11-19T10:29:01Z")

</div>

I have looked at this for so long I’ve lost perspective 🙂

I think I will cut this down to a simpler problem and compile just LibreSSL (my favorite toy CMake project) and see if I can compile it in the pipeline

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [November 19, 2024, 10:30am UTC](https://discourse.cmake.org/t/cmake-linker-type-when-cross-compiling-not-passing-correct-options/12985/7 "2024-11-19T10:30:29Z")

</div>

By the way, are you sure that a target specification is not required? From the `CMake` documentation regarding [cross-compiling with `clang`](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-using-clang), variable `CMAKE_<LANG>_COMPILER_TARGET` should be defined to let clang know how to compile for the needed target.
