external dep lib dir
Some checks failed
CI / build-test-release (push) Failing after 13m55s

This commit is contained in:
Jorijn van der Graaf 2026-05-06 03:59:19 +02:00
commit 659103a123
2 changed files with 21 additions and 1 deletions

View file

@ -269,7 +269,20 @@ ExternalBuildResult Crafter::BuildExternal(
}
if (dep.builder == ExternalBuilder::CMake) {
result.linkFlags.push_back(std::format("-L{}", fs::absolute(cmakeBuildDir).string()));
// Each search path gets both a -L (link-time) and a -Wl,-rpath
// (runtime-loader). The rpath stays embedded in the produced
// binary so it picks up shared deps from the cache without any
// LD_LIBRARY_PATH gymnastics. Static deps (.a) ignore the rpath
// harmlessly.
std::string buildDirAbs = fs::absolute(cmakeBuildDir).string();
result.linkFlags.push_back(std::format("-L{}", buildDirAbs));
result.linkFlags.push_back(std::format("-Wl,-rpath,{}", buildDirAbs));
for (const fs::path& libDir : dep.libDirs) {
fs::path full = libDir.is_absolute() ? libDir : cmakeBuildDir / libDir;
std::string fullAbs = fs::absolute(full).string();
result.linkFlags.push_back(std::format("-L{}", fullAbs));
result.linkFlags.push_back(std::format("-Wl,-rpath,{}", fullAbs));
}
for (const std::string& lib : dep.libs) {
result.linkFlags.push_back(std::format("-l{}", lib));
}