[llvm-dev] Statically linking against libc++
Dimitry Andric via llvm-dev
llvm-dev at lists.llvm.org
Sun Apr 9 09:49:54 PDT 2017
On 9 Apr 2017, at 18:05, Carsten Mattner via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> While considering statically linking against libc++ (and
> other runtime libraries from LLVM), I rebuilt LLVM 4.0
> with -DBUILD_SHARED_LIBS=OFF.
> There are still some .so's in llvm/lib, and only one
> of them seems to exist exclusively as a DSO (libLTO).
> There's also livLLVMLTO.a, but I doubt LTO is used
> after linking a binary so this just looks odd to an
> uninformed LLVM outside and not insufficient or anything.
> My question is two-fold:
> 1. when building a C++ program with clang, maybe making use
> of clang-musl to avoid glibc as well, how do I statically
> link libc++ and get a C++ program that runs on any Linux
> kernel, allowing easy distribution of a single binary?
If you want to link just libc++ statically, you can use:
-Wl,-Bstatic -lc++ -Wl,-Bdynamic
in your link flags. Otherwise, just use -static.
> 2. should the following .so's be built with -DBUILD_SHARED_LIBS=OFF?
> $ ls *.so
Indeed, those should probably be cleaned up. On the other hand, some
libraries do not really make sense as static ones, so those could be
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 194 bytes
Desc: Message signed with OpenPGP
More information about the llvm-dev