================
@@ -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++
----------------
da-viper wrote:
>From my reading, looks like the two are synonymous.
`nostdlib` is for `C` standard library and `nostdlib++` is for `C++` standard
library
>But you're saying we need -lnostdlib++ ?
No, currently the `LD_FLAGS` is treated as args to pass to the `linker command`
not list of libraries to link.
It from clang. because if you use clang as a liker it will implicitly link to
the host stdlib
```sh
$ clang++ -c -stdlib=libc++ main.cpp -o main.o
$ clang++ main.o -o main -v # will link using the host stdlib
# result
Ubuntu clang version 20.1.2 (0ubuntu1)
....
"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m
elf_x86_64
-pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main
/lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/14/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/14
-L/usr/lib/gcc/x86_64-linux-gnu/14/../../../../lib64
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
-L/usr/lib/../lib64 -L/lib -L/usr/lib test.o
**-lstdc++** -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-linux-gnu/14/crtendS.o
/lib/x86_64-linux-gnu/crtn.o
```
if you specify the stdlib link library `-lc++` it will link to both the host
and the library you specified
```sh
[work:~/Dev/scratch/test_process]$ /usr/bin/clang++ test.o -o main -lc++ -v
Ubuntu clang version 20.1.2 (0ubuntu1)
...
"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m
elf_x86_64
-pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main
/lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/14/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/14
-L/usr/lib/gcc/x86_64-linux-gnu/14/../../../../lib64
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
-L/usr/lib/../lib64 -L/lib -L/usr/lib test.o
**-lc++** **-lstdc++** -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-linux-gnu/14/crtendS.o
/lib/x86_64-linux-gnu/crtn.o
```
normally we specify the stdlib when linking to use the correct one
```sh
$ clang++ -stdlib=libc++ main.o -o main
```
but in this case we may not be sure what stdlib we are using so we specify
`-nostdlib++` and set the link library manually.
https://github.com/llvm/llvm-project/pull/164462
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits