clang -fsanitize=address 无法找到 libclang_rt.asan

huangapple go评论89阅读模式
英文:

clang -fsanitize=address can't find libclang_rt.asan

问题

这是代码部分,不需要翻译。

英文:

It was my first time building clang from source, so maybe I messed it up, but if I try to compile a "hello world" with -fsanitize=address, I get an error:

$ clang -fsanitize=address hello.c 
/usr/bin/ld: cannot find /usr/local/lib/clang/15.0.7/lib/linux/libclang_rt.asan_static-x86_64.a: No such file or directory
/usr/bin/ld: cannot find /usr/local/lib/clang/15.0.7/lib/linux/libclang_rt.asan-x86_64.a: No such file or directory
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

In fact, /usr/local/lib/clang/15.0.7/lib doesn't exist at all (only include/ there). Did I build clang incorrectly? These are the commands I used, on Debian Stable:

wget "https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/llvm-project-15.0.7.src.tar.xz"
tar xvf llvm-project-15.0.7.src.tar.xz
cd llvm-project-15.0.7.src
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release
ninja -C build check-llvm
sudo ninja -C build install

答案1

得分: 0

注释很有帮助。我将留下答案,以防其他人遇到此问题并通过谷歌找到这篇帖子。

解决方法是在 `cmake` 命令中添加 `-DLLVM_ENABLE_RUNTIMES=all`。例如,完整的构建说明可以是

    tar xvf llvm-project-15.0.7.src.tar.xz
    cd llvm-project-15.0.7.src
    cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES=all
    ninja -C build check-llvm  
    sudo ninja -C build install
英文:

The comments helped. I'm going to leave an answer in case someone else has this problem and finds this post by googling.

The solution is to add -DLLVM_ENABLE_RUNTIMES=all to the cmake command. For example, the complete build instructions can be

tar xvf llvm-project-15.0.7.src.tar.xz
cd llvm-project-15.0.7.src
cmake -S llvm -B build -G Ninja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES=all
ninja -C build check-llvm  
sudo ninja -C build install

huangapple
  • 本文由 发表于 2023年3月12日 15:48:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定