Skip to content

Commit dd6c932

Browse files
committed
fix: explicitly link libc++ on macOS for Clang toolchain
xlings LLVM's clang++.cfg uses -nostdinc++ which suppresses the implicit -lc++ that clang++ normally adds during linking. This causes undefined symbol errors for C++ stdlib types. Fix by explicitly adding -lc++ to link flags on macOS.
1 parent d37bbc3 commit dd6c932

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/build/flags.cppm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,15 @@ CompileFlags compute_flags(const BuildPlan& plan) {
161161
runtime_dirs += " -L" + escape_path(dir);
162162
runtime_dirs += " -Wl,-rpath," + escape_path(dir);
163163
}
164-
f.ld = std::format("{}{}{}{}{}", full_static, static_stdlib, sysroot_flag, b_flag,
165-
runtime_dirs);
164+
#if defined(__APPLE__)
165+
// macOS: explicitly link libc++ — xlings LLVM's cfg uses -nostdinc++
166+
// which may suppress the implicit -lc++ that clang++ normally adds.
167+
std::string stdlib_link = isClang ? " -lc++" : "";
168+
#else
169+
std::string stdlib_link;
170+
#endif
171+
f.ld = std::format("{}{}{}{}{}{}", full_static, static_stdlib, sysroot_flag, b_flag,
172+
runtime_dirs, stdlib_link);
166173

167174
return f;
168175
}

0 commit comments

Comments
 (0)