[Lldb-commits] [lldb] [lldb][test] When an external stdlib is specified do not link to the system stdlib (PR #164462)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 21 11:18:58 PDT 2025


================
@@ -386,6 +386,11 @@ ifeq (,$(filter 1, $(USE_LIBSTDCPP) $(USE_LIBCPP) $(USE_SYSTEM_STDLIB)))
     ifneq "$(LIBCPP_INCLUDE_TARGET_DIR)" ""
       CXXFLAGS += -cxx-isystem $(LIBCPP_INCLUDE_TARGET_DIR)
     endif
+
+	# If `-nostdlib++` is not passed, clang will link to the system's stdlib.
+	ifeq ($(LDC), clang)
+		LDFLAGS += -nostdlib++ -nostdinc++
----------------
Michael137 wrote:

So it seems like `nostdlib++` is undocumented: https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-nostdlib

But there is also [`-nostdlib`/`--no-standard-libraries`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-nostdlib). Which is also not documented.

>From my reading, looks like the two are synonymous. When specified, Clang won't add the `-lc++`/`-lstdc++` flags.

But you're saying we need `-lnostdlib++`? That sounds like it is the underlying linker that Clang ends up invoking that needs this. I see GNU LD supports these: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html. Is that why we need them on Linux?

https://github.com/llvm/llvm-project/pull/164462


More information about the lldb-commits mailing list