You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
LLVM-%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95/
使用自编译的C++标准库
不想使用系统自带的 C++ 库,需要自己编译一套 llvm 的 libc++.so 以及 STL 的时候,可以参考如下命令:
1
2
3
4
5
6
7
8
9
10
11
cmake -G Ninja
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lldb;lld"
-DLLVM_ENABLE_RUNTIMES="libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload"
-DLIBCXX_ENABLE_SHARED=ON
-DLIBCXXABI_ENABLE_SHARED=ON
-DLLVM_USE_LINKER=lld
-DCMAKE_BUILD_TYPE=Release
-DLLVM_BUILD_LLVM_DYLIB=ON
-DLLVM_LINK_LLVM_DYLIB=ON
-DCMAKE_INSTALL_PREFIX=/home/debian/tools/clang-llvm-21
../llvm-project/llvm
编译完库之后,使用显式参数告诉clang++使用自编译库:
1
clang++ -stdlib=libc++ test.cpp -o test
使用ripgrep查找libc++.so所在目录:
1
2
3
4
5
6
7
8
9
debian@debian:~/tools/clang-llvm-21$ rg --files | rg so | rg "libc++"
share/libc++/v1/std/memory_resource.inc
share/libc++/v1/std/source_location.inc
lib/libclang.so.21.0.0git
lib/aarch64-unknown-linux-gnu/libc++abi.so.1.0
lib/aarch64-unknown-linux-gnu/libc++.so
lib/aarch64-unknown-linux-gnu/libc++.modules.json
lib/aarch64-unknown-linux-gnu/libc++.so.1.0
lib/libclang-cpp.so.21.0git
使用ldd或者运行可执行文件test之前,需要先注入环境变量:
https://hcy-asleep.github.io/LLVM-%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95/
Beta Was this translation helpful? Give feedback.
All reactions