Open h-2 opened 9 months ago
You are linking libc++, so the option only applies to the GNU specific libstdc++ (which is default on Linux). Unfortunately there seems to be no equivalent -static-libc++
option. You may have to play games with -Wl,-Bstatic
, though I am unsure if that will work as expected on macOS. (In general, static linking is discouraged on macOS, it seems.)
You are linking libc++, so the option only applies to the GNU specific libstdc++ (which is default on Linux).
On Linux, -static-libstdc++ -stdlib=libc++
statically links libc++. So at least on Linux, the option refers to whatever c++ standard library is used.
(In general, static linking is discouraged on macOS, it seems.)
Yeah, we don't want to statically link system stuff, but the libc++ is effectively an application dependency when used from homebrew.
@llvm/issue-subscribers-clang-driver
Author: Hannes Hauswedell (h-2)
It's orthogonal to the chosen standard library (irrelevant to either libc++ or libstdc++).
The Darwin toolchain doesn't contain the logic found in the GNU counterpart, probably due to the lack of -Bstatic
counterpart in ld64:
Hardcoding it in the linker arguments is likely the way to go for your use case (no -stdlib=libc++
and no change to compiler options):
-nostdlib++ -Wl,/opt/homebrew/opt/llvm/lib/c++/libc++.a,/opt/homebrew/opt/llvm/lib/c++/libc++abi.a
Alternatively, you can download and build libc++ as a dependency like so: https://github.com/poyaoc97/cxxlab/blob/main/cmake/FetchLibcxx.cmake.
We are building mac binaries with llvm17 installed from homebrew. The built binaries depend on
/opt/homebrew/opt/llvm/lib/c++/libc++.1.dylib
. We would like the binaries to not depend on the presence of homebrew, therefore we added-static-libstdc++
to the build, but this is ignored:On Linux this works. What are we doing wrong?