This is an archive of the discontinued LLVM Phabricator instance.

Add support in CMake to statically link the C++ standard library.
ClosedPublic

Authored by erichkeane on Aug 1 2019, 1:04 PM.

Details

Summary

It is sometimes useful to have the C++ standard library linked into the
assembly when compiling clang, particularly when distributing a compiler
onto systems that don't have a copy of stdlibc++ or libc++ installed.

This functionality should work with either GCC or Clang as the host
compiler, though statically linking libc++ (as may be required for
licensing purposes) is only possible if the host compiler is Clang with
a copy of libc++ available.

Diff Detail

Repository
rL LLVM

Event Timeline

erichkeane created this revision.Aug 1 2019, 1:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2019, 1:04 PM
Herald added a subscriber: mgorny. · View Herald Transcript

Unfortunately, this ends up adding a warning or two to the build if you enable this, since we have a couple of things built in "C" (flag not used...). In the 'clang' test I did, ./bin/count was the only one. Unfortunately, we don't have separate C vs C++ linking flags, so I think this is just something that someone using this flag needs to deal with.

Does anyone have issues with this? Can I commit it?

This revision was not accepted when it landed; it landed in state Needs Review.Aug 14 2019, 12:55 PM
This revision was automatically updated to reflect the committed changes.

Does anyone have issues with this? Can I commit it?

@erichkeane
I think the problem is that LLVM_STATIC_LINK_CXX_STDLIB may be too niche. Do people want to set CMAKE_SHARED_LINKER_FLAGS at the same time? On Linux, unless you set LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY, -static-libstdc++ -stdlib=libc++ does not really work. Considering all these, I do not know whether the configure time variable pulls its weight. Personally I'd avoid such complexity.