<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68513>68513</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][build] Error: The install of the * target requires changing an RPATH (mingw)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ilg-ul
</td>
</tr>
</table>
<pre>
While compiling 17.0.2 for Windows using a bootstrap compiler, I got the following error:
```console
[136/5530] cd /home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/x86_64-w64-mingw32/build/llvm-17.0.2/NATIVE && /home/ilg/.local/xPacks/@xpack-dev-tools/cmake/3.26.5-1.1/.content/bin/cmake -G Ninja -DCMAKE_MAKE_PROGRAM="/home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/xpacks/.bin/ninja" -DCMAKE_C_COMPILER_LAUNCHER="" -DCMAKE_CXX_COMPILER_LAUNCHER="" /home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/sources/llvm-project-17.0.2.src/llvm -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="" -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-w64-mingw32" -DLLVM_TARGET_ARCH="host" -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;clang-tools-extra;polly" -DLLVM_EXTERNAL_PROJECTS="" -DLLVM_ENABLE_RUNTIMES="" -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="OFF" -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_CLANG_SOURCE_DIR=/home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/sources/llvm-project-17.0.2.src/llvm/../clang
FAILED: NATIVE/CMakeCache.txt /home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/x86_64-w64-mingw32/build/llvm-17.0.2/NATIVE/CMakeCache.txt
cd /home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/x86_64-w64-mingw32/build/llvm-17.0.2/NATIVE && /home/ilg/.local/xPacks/@xpack-dev-tools/cmake/3.26.5-1.1/.content/bin/cmake -G Ninja -DCMAKE_MAKE_PROGRAM="/home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/xpacks/.bin/ninja" -DCMAKE_C_COMPILER_LAUNCHER="" -DCMAKE_CXX_COMPILER_LAUNCHER="" /home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/sources/llvm-project-17.0.2.src/llvm -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="" -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-w64-mingw32" -DLLVM_TARGET_ARCH="host" -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;clang-tools-extra;polly" -DLLVM_EXTERNAL_PROJECTS="" -DLLVM_ENABLE_RUNTIMES="" -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="OFF" -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_EXTERNAL_CLANG_SOURCE_DIR=/home/ilg/Work/xpack-dev-tools/clang-xpack.git/build/win32-x64/sources/llvm-project-17.0.2.src/llvm/../clang
-- The C compiler identification is Clang 17.0.2
-- The CXX compiler identification is Clang 17.0.2
-- The ASM compiler identification is Clang with GNU-like command-line
...
-- Configuring done (18.2s)
CMake Error at cmake/modules/AddLLVM.cmake:967 (add_executable):
The install of the llvm-tblgen target requires changing an RPATH from the
build tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
Call Stack (most recent call first):
cmake/modules/TableGen.cmake:146 (add_llvm_executable)
utils/TableGen/CMakeLists.txt:33 (add_tablegen)
CMake Error at cmake/modules/AddLLVM.cmake:588 (add_library):
The install of the LTO target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:848 (llvm_add_library)
tools/lto/CMakeLists.txt:32 (add_llvm_library)
CMake Error at cmake/modules/AddLLVM.cmake:588 (add_library):
The install of the LTO target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:848 (llvm_add_library)
tools/lto/CMakeLists.txt:32 (add_llvm_library)
CMake Error at cmake/modules/AddLLVM.cmake:967 (add_executable):
The install of the llvm-ar target requires changing an RPATH from the build
tree, but this is not supported with the Ninja generator unless on an
ELF-based or XCOFF-based platform. The CMAKE_BUILD_WITH_INSTALL_RPATH
variable may be set to avoid this relinking step.
Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:1350 (add_llvm_executable)
cmake/modules/AddLLVM.cmake:1375 (llvm_add_tool)
tools/llvm-ar/CMakeLists.txt:14 (add_llvm_tool)
... and so on, lots of them...
```
My solution was to add `CMAKE_BUILD_WITH_INSTALL_RPATH=ON` to the top CMakeLists.txt, and to patch
`CrossCompile.cmake` to propagate the `CMAKE_BUILD_WITH_INSTALL_RPATH` variable down to the sub-build:
```
>From ee0b12eaed9adb713793c9e286bbb2d9016ecd9f Mon Sep 17 00:00:00 2001
From: Liviu Ionescu <ilg@livius.net>
Date: Fri, 6 Oct 2023 15:46:21 +0300
Subject: [PATCH] CrossCompile.cmake: propagate CMAKE_BUILD_WITH_INSTALL_RPATH
---
llvm/cmake/modules/CrossCompile.cmake | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/cmake/modules/CrossCompile.cmake b/llvm/cmake/modules/CrossCompile.cmake
index 6af47b51d4c6..9c607f1a7590 100644
--- a/llvm/cmake/modules/CrossCompile.cmake
+++ b/llvm/cmake/modules/CrossCompile.cmake
@@ -74,6 +74,7 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype)
-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR}
${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
+ -DCMAKE_BUILD_WITH_INSTALL_RPATH="${CMAKE_BUILD_WITH_INSTALL_RPATH}"
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
-DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}"
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}"
--
2.37.1 (Apple Git-137.1)
```
Martin, @mstorsjo, what do think about this issue? Should I submit a PR?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWV9vq7gS_zTuiwUC8y956APhT5u7JKkI3dN9QgYc4lPHzgVz2n77KwNJ0zZn23NU7UpXlSrU4pnxb2Z-zIxd3La05oRcAmcGnPACd3IrmkvKaq1jF4Woni6_bSkjsBS7PWWU19D0dENHcCMa-I3ySjy0sGvVAoaFELKVDd6P4qQBKIBzWAsJ5ZbAjWBMPChZ0jSiAZYPjBAYh6drDD-l4K1gZHzrzEzLBSh2HMsATgjLCgIUb8WOABRTVgMUfxPNPUDx4x6X91pFfmhSCNYCFJcM81rr3-s1lQDFRUdZBVD8QLmFtEfXVnoTN3dt7cG1tR3l9YOFTgQZ-7HTBp8Bipd-Nv8zggC5ALlvcOhMlJgpize4vFcAgG2cQbXD90rJ0pGrO5qp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