我最近切换到 ubuntu (20.04.2 LTS) 并尝试安装 clang (和 clang++)。我用以下方法做到了:
sudo apt-get install clang
并可以在 /usr/bin 中找到 clang 和 clang++
当我尝试编译任何程序时,我收到“分段错误”。 (我确实编译了一个简单的程序,用 g++ 打印“hello”并且它有效)。我使用的命令是:
clang++ -o hello hello.cpp
有谁能够帮助我?
我已经尝试卸载并重新安装它,但到目前为止没有任何效果。
(仅供参考,代码为:
#include <iostream>
int main(int argc, char** argv){
std::cout << "Hello\n";
return 0;
}
)
如果有任何帮助,ldd which clang++
请输出以下内容:
linux-vdso.so.1 (0x00007ffcc09b2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f30f14ea000)
libclang-cpp.so.10 => /usr/local/llvm-10/lib/libclang-cpp.so.10 (0x00007f30edfcc000)
libLLVM-10.so.1 => /lib/x86_64-linux-gnu/libLLVM-10.so.1 (0x00007f30e9938000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f30e9757000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f30e9608000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f30e95ed000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f30e93f9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f30f1532000)
libLLVMCoroutines.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMCoroutines.so.10 (0x00007f30e93c1000)
libLLVMCoverage.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMCoverage.so.10 (0x00007f30e9391000)
libLLVMFrontendOpenMP.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMFrontendOpenMP.so.10 (0x00007f30e937c000)
libLLVMLTO.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMLTO.so.10 (0x00007f30e9308000)
libLLVMObjCARCOpts.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMObjCARCOpts.so.10 (0x00007f30e92d6000)
libLLVMPasses.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMPasses.so.10 (0x00007f30e9185000)
libLLVMOption.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMOption.so.10 (0x00007f30e9171000)
libLLVMipo.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMipo.so.10 (0x00007f30e8f57000)
libLLVMIRReader.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMIRReader.so.10 (0x00007f30e8f4d000)
libLLVMMCJIT.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMMCJIT.so.10 (0x00007f30e8f3a000)
libLLVMInstrumentation.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMInstrumentation.so.10 (0x00007f30e8dfe000)
libLLVMLinker.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMLinker.so.10 (0x00007f30e8dd4000)
libLLVMBitWriter.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMBitWriter.so.10 (0x00007f30e8d84000)
libLLVMScalarOpts.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMScalarOpts.so.10 (0x00007f30e89eb000)
libLLVMInstCombine.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMInstCombine.so.10 (0x00007f30e8891000)
libLLVMTransformUtils.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMTransformUtils.so.10 (0x00007f30e8664000)
libLLVMExecutionEngine.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMExecutionEngine.so.10 (0x00007f30e8639000)
libLLVMTarget.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMTarget.so.10 (0x00007f30e8626000)
libLLVMAnalysis.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMAnalysis.so.10 (0x00007f30e81be000)
libLLVMProfileData.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMProfileData.so.10 (0x00007f30e813b000)
libLLVMObject.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMObject.so.10 (0x00007f30e8004000)
libLLVMMCParser.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMMCParser.so.10 (0x00007f30e7fa9000)
libLLVMMC.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMMC.so.10 (0x00007f30e7ebe000)
libLLVMBitReader.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMBitReader.so.10 (0x00007f30e7e32000)
libLLVMCore.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMCore.so.10 (0x00007f30e7adb000)
libLLVMBitstreamReader.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMBitstreamReader.so.10 (0x00007f30e7ac3000)
libLLVMSupport.so.10 => /usr/local/llvm-10/lib/../lib/libLLVMSupport.so.10 (0x00007f30e7890000)
libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007f30e7884000)
libedit.so.2 => /lib/x86_64-linux-gnu/libedit.so.2 (0x00007f30e784a000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f30e782e000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f30e7823000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f30e781d000)
libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f30e77ed000)
libLLVMCodeGen.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMCodeGen.so.10 (0x00007f30e7250000)
libLLVMAggressiveInstCombine.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMAggressiveInstCombine.so.10 (0x00007f30e7237000)
libLLVMVectorize.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMVectorize.so.10 (0x00007f30e7138000)
libLLVMAsmParser.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMAsmParser.so.10 (0x00007f30e70b3000)
libLLVMRuntimeDyld.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMRuntimeDyld.so.10 (0x00007f30e701e000)
libLLVMBinaryFormat.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMBinaryFormat.so.10 (0x00007f30e6ff9000)
libLLVMTextAPI.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMTextAPI.so.10 (0x00007f30e6fc1000)
libLLVMRemarks.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMRemarks.so.10 (0x00007f30e6f7f000)
libz3.so.4 => /lib/x86_64-linux-gnu/libz3.so.4 (0x00007f30e59df000)
libLLVMDemangle.so.10 => /usr/local/llvm-10/lib/../lib/../lib/libLLVMDemangle.so.10 (0x00007f30e5994000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f30e597a000)
答案1
正如评论中所述,您在 中存在一些问题/usr/local
,并且由于某种原因(错误的环境变量LD_LIBRARY_PATH
等?),它们似乎在/usr/lib
或下的官方变量之前/而不是被选中/usr/lib64
。
用于ldd(1)
找出您/usr/bin/clang
正在尝试加载哪些库。
你说你尝试从 git 安装,默认情况clang
下会安装。/usr/local/
使用locate(1)
或find(1)
查找有问题的文件(错误消息指出了很多可疑之处),检查该文件是否属于重要的内容/是由您的包管理器安装的文件(我对 Ubuntu 不熟悉,一些 Debian 人员可能会提供这样做的咒语),删除(或藏起来,例如/var/tmp/usr/local/...
以跟踪原始位置)并重试。