@@ -19,6 +19,12 @@ export namespace mcpp::platform::linux_ {
1919std::string build_ld_library_path_prefix (
2020 const std::vector<std::filesystem::path>& dirs);
2121
22+ // Build an LD_LIBRARY_PATH shell prefix for toolchain host processes.
23+ // Unlike build_ld_library_path_prefix(), this does not append inherited
24+ // LD_LIBRARY_PATH, which may contain target-program runtime directories.
25+ std::string build_clean_ld_library_path_prefix (
26+ const std::vector<std::filesystem::path>& dirs);
27+
2228// Return Linux toolchain runtime library directories.
2329std::vector<std::filesystem::path>
2430runtime_lib_dirs (const std::filesystem::path& toolchain_root);
@@ -29,16 +35,24 @@ runtime_lib_dirs(const std::filesystem::path& toolchain_root);
2935
3036namespace mcpp ::platform::linux_ {
3137
32- std::string build_ld_library_path_prefix (
33- const std::vector<std::filesystem::path>& dirs)
34- {
35- #if defined(__linux__)
36- if (dirs.empty ()) return " " ;
38+ namespace {
39+
40+ std::string join_dirs (const std::vector<std::filesystem::path>& dirs) {
3741 std::string joined;
3842 for (auto & d : dirs) {
3943 if (!joined.empty ()) joined += ' :' ;
4044 joined += d.string ();
4145 }
46+ return joined;
47+ }
48+
49+ } // namespace
50+
51+ std::string build_ld_library_path_prefix (
52+ const std::vector<std::filesystem::path>& dirs) {
53+ #if defined(__linux__)
54+ if (dirs.empty ()) return " " ;
55+ auto joined = join_dirs (dirs);
4256 return std::format (" env LD_LIBRARY_PATH={}${{LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}} " ,
4357 mcpp::platform::shell::quote (joined));
4458#else
@@ -47,6 +61,19 @@ std::string build_ld_library_path_prefix(
4761#endif
4862}
4963
64+ std::string build_clean_ld_library_path_prefix (
65+ const std::vector<std::filesystem::path>& dirs) {
66+ #if defined(__linux__)
67+ if (dirs.empty ()) return " " ;
68+ auto joined = join_dirs (dirs);
69+ return std::format (" env LD_LIBRARY_PATH={} " ,
70+ mcpp::platform::shell::quote (joined));
71+ #else
72+ (void )dirs;
73+ return " " ;
74+ #endif
75+ }
76+
5077std::vector<std::filesystem::path>
5178runtime_lib_dirs (const std::filesystem::path& toolchain_root) {
5279 std::vector<std::filesystem::path> dirs;
0 commit comments