[llvm-dev] Statically linking against libc++

Carsten Mattner via llvm-dev llvm-dev at lists.llvm.org
Sun Apr 9 20:31:25 PDT 2017

On Sun, Apr 9, 2017 at 4:49 PM, Dimitry Andric wrote:
> Otherwise, just use -static.

So obvious and easy. I'm so used (stockholm syndrome?)
to not being able to link Linux (aka glibc+libstd++)
statically that I didn't expect this.

I'm surprised this clang++ foo.cc -static -o foo
produced a foo that doesn't required glibc. I would
have thought that this would have failed to link
without involving musl, which I don't know how to
include since musl outside a musl chroot/distro
only has musl-clang for building C code without
the C++ frontend, where one probably needs to
explicitly add -lc++.

foo.cc wasn't tiny either, it includes fcntl.h,
sys/*.h, etc., in addition to the C++ standard
lib headers.

I'm on Arch Linux where there isn't any .a like
you would get on Gentoo or Debian's -dev packages,
so I wonder how this linked statically without me
telling it to use musl libc for the C symbols.
Do you know why?

More information about the llvm-dev mailing list