Reputation: 21
I trying to link statically the standard library libc++ (https://libcxx.llvm.org/) in Linux (Arch using this AUR https://aur.archlinux.org/packages/libc%2B%2B/) using Clang.
I get the error /usr/bin/ld: cannot find -lc++
The error is independent from the code, it appears even in a "Hello World".
If I remove the -static
option it compiles (and links) and the generated executable works.
I don't want to use libstdc++ (I have my reasons not to please not focus the discussion in this) and the linking must be static (it's a requirement).
I'm perfectly aware that it's difficult to debug this stuff without having access to the machine where it happens. However, it happens it two different machines (both with Arch) so maybe it's something I'm forgetting about.
What I have tried so far is explained here (https://releases.llvm.org/7.0.0/projects/libcxx/docs/UsingLibcxx.html)
The basic command that shoud work it's the following
clang++ -static -stdlib=libc++ -std=c++17 main.cpp -lc++abi
Upvotes: 2
Views: 4076
Reputation: 61590
That will be because you do not have a static libc++
(i.e. libc++.a
) installed
on your system. Archlinux defaulted to not installing static libraries 5 years ago,
so it will be challenging for you to perform fully static linkages. You will
have to make your own static builds of all dependent libraries, recursively.
Upvotes: 1