Skip to content

prTollvm

923字约3分钟

2025-03-24

构建libcxx

cmake -G Ninja -S llvm-project/runtimes -B build  \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind \
-DCMAKE_SYSROOT="D:\workfile\compiler\clang\x86_64-windows-gnu" \
-DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" 

cmake -G"Ninja" -S llvm-project/runtimes -B build  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld  -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld"


cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-msvc" -DCMAKE_SYSROOT="D:\workfile\compiler\windows-msvc-sysroot" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib"


cmake -G Ninja -S llvm-project/runtimes -B build 
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" 
-DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" 
-DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" 
-DLLVM_USE_LINKER=lld 
-DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" 
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" 
-DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" 
-DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib"
-DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll "
-DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -lc++abi -lunwind -lntdll -stdlib=libc++ -std=c++23"

cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -lc++abi -lunwind -lntdll -stdlib=libc++ -std=c++23"

//动态链接 构建libcxx;libcxxabi;libunwind
cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt   -Wno-unused-command-line-argument" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt   -stdlib=libc++  -Wno-unused-command-line-argument" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON
//报错
/*ld.lld: error: undefined symbol: std::__1::__libcpp_condvar_wait(void**, void**)
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_guard.cpp.obj:(__cxxabiv1::(anonymous namespace)::LibcppCondVar::wait(__cxxabiv1::(anonymous namespace)::LibcppMutex&))

ld.lld: error: undefined symbol: std::__1::__libcpp_mutex_lock(void**)
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_guard.cpp.obj:(__cxxabiv1::(anonymous namespace)::LibcppMutex::lock())
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/fallback_malloc.cpp.obj:((anonymous namespace)::mutexor::mutexor(void**))

ld.lld: error: undefined symbol: std::__1::__libcpp_mutex_unlock(void**)
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_guard.cpp.obj:(__cxxabiv1::(anonymous namespace)::LibcppMutex::unlock())
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/fallback_malloc.cpp.obj:((anonymous namespace)::mutexor::~mutexor())

ld.lld: error: undefined symbol: std::__1::__libcpp_condvar_broadcast(void**)
>>> referenced by libcxxabi/src/CMakeFiles/cxxabi_shared_objects.dir/cxa_guard.cpp.obj:(__cxxabiv1::(anonymous namespace)::LibcppCondVar::broadcast())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
*/

//动态链接
cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -lc++abi -lunwind -lntdll -stdlib=libc++ -std=c++23" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON 

//静态库链接
cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -Wno-unused-command-line-argument" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -stdlib=libc++  -Wno-unused-command-line-argument" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXXABI_ENABLE_SHARED=OFF -DLIBCXXABI_ENABLE_STATIC=ON -DLIBCXXABI_ENABLE_SHARED=ON  -DLIBCXXABI_USE_LLVM_UNWINDER=ON

//新加参数 
cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -lunwind -lntdll" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind   -lunwind -lntdll -stdlib=libc++ -std=c++23" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON 

//单libcxx 动态链接 
cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_PROJECTS="libcxx" -DLLVM_ENABLE_RUNTIMES="libcxx" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu" -DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu" -DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -unwindlib=libunwind  -lc++abi -lunwind -lntdll -stdlib=libc++ -std=c++23" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON
//报错
// In file included from D:/workfile/github/llvm-libcxx/llvm-project/libcxx/src/stdexcept.cpp:17:
// D:/workfile/github/llvm-libcxx/llvm-project/libcxx/src/support/runtime/stdexcept_default.ipp:13:12: fatal error: 'cxxabi.h' file not found
//    13 | #  include <cxxabi.h>
//       |            ^~~~~~~~~~



cmake -G Ninja -S llvm-project/runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" -DLLVM_RUNTIME_TARGETS="x86_64-windows-gnu"-DCMAKE_SYSROOT="D:/workfile/compiler/clang/x86_64-windows-gnu"-DLLVM_USE_LINKER=lld -DCMAKE_LINKER="D:/workfile/compiler/clang/llvm/bin/lld" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib -Wl,-lkernel32" -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib -Wl,-lkernel32" -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld -L${CMAKE_SYSROOT}/lib -Wl,-lkernel32" -DCMAKE_C_FLAGS="-rtlib=compiler-rt -Wno-unused-command-line-argument" -DCMAKE_CXX_FLAGS="-rtlib=compiler-rt -stdlib=libc++ -D_WIN32_WINNT=0x0600 -Wno-unused-command-line-argument" -DCMAKE_INSTALL_PREFIX="D:/workfile/lib/llvm" -DLIBCXX_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_SHARED=ON -DLIBCXXABI_ENABLE_STATIC=OFF -DLIBCXXABI_USE_LLVM_UNWINDER=ON