降级libc6引发依赖冲突,无法安装clang及编译librockdb-sys
问题背景
搭建本地服务器时,编译librockdb-sys v6.20.3失败,报错提示无法找到libclang,需设置LIBCLANG_PATH环境变量。尝试安装clang时,遇到libc6版本冲突:libc6-i386依赖libc6=2.31-0ubuntu9.9,但当前系统libc6版本为2.33-0ubuntu5,降级libc6会导致删除1269个关键系统包,无法执行。
编译错误详情
Compiling serde_json v1.0.79
Compiling bincode v1.3.3
Compiling secp256k1 v0.22.1
Compiling hyperlocal v0.8.0
error: failed to run custom build command for 'librocksdb-sys v6.20.3'Caused by: process didn't exit successfully:
/home/softwarehouse/electrs/target/release/build/librocksdb-sys-cc5b955581598a2f/build-script-build
(exit status: 101) --- stderr thread 'main' panicked at 'Unable to
find libclang: "couldn't find any valid shared libraries matching:
['libclang.so', 'libclang-.so', 'libclang.so.', 'libclang-.so.'],
set theLIBCLANG_PATHenvironment variable to a path where one of
these files can be found (invalid: [])"',
/home/softwarehouse/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.59.2/src/lib.rs:2144:31
note: run withRUST_BACKTRACE=1environment variable to display a
backtrace warning: build failed, waiting for other jobs to finish...
安装clang错误详情
(base) user@user:~/electrs$ sudo apt install clang
Reading package lists...
Done Building dependency tree...
Done Reading state information...
Done Some packages could not be installed.This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following
information may help to resolve the situation:The following packages have unmet dependencies:
libc6-i386 : Depends: libc6 (= 2.31-0ubuntu9.9) but 2.33-0ubuntu5 is to be installedE: Unable to correct problems, you have held broken packages.
降级libc6提示
0 upgraded, 0 newly installed, 1 downgraded, 1269 to remove and 0 not
upgraded.Need to get 2 722 kB of archives. After this operation,
4 691 MB disk space will be freed. You are about to do something
potentially harmful.To continue type in the phrase 'Yes, do as I say!'
解决方案
方案1:用aptitude解决依赖冲突
aptitude比apt更擅长处理复杂依赖问题,会提供替代安装方案:
- 安装aptitude:
sudo apt install aptitude - 执行clang安装命令:
sudo aptitude install clang - 当aptitude提示解决方案时,第一个方案通常是降级libc6,输入
n拒绝;第二个方案会跳过冲突的32位依赖包,只安装64位clang组件,输入y确认即可。
方案2:手动安装clang预编译包(不依赖系统包)
直接下载llvm官方预编译的clang,避免系统依赖问题:
- 下载对应Ubuntu版本的clang预编译包(选择适合你系统架构的版本,比如x86_64)
- 解压到本地目录,例如:
tar -xzf clang+llvm-*.tar.xz -C ~/ mv ~/clang+llvm-* ~/clang - 设置环境变量指向clang的库目录,然后执行编译:
(如果需要永久生效,可将export命令添加到export LIBCLANG_PATH=~/clang/lib cargo build --release~/.bashrc或~/.zshrc)
方案3:指定安装64位clang
明确指定安装amd64架构的clang,避免拉取32位依赖:
sudo apt install clang:amd64
如果仍有依赖问题,可尝试安装特定版本的clang,先查看可用版本:
apt-cache madison clang
然后选择一个与系统libc6版本兼容的版本安装,例如:
sudo apt install clang=14.0.0-1ubuntu1
方案4:使用系统已有的llvm库(如果存在)
检查系统是否已安装llvm相关库:
find /usr/lib -name "libclang.so*"
如果找到路径,比如/usr/lib/llvm-14/lib/libclang.so,直接设置环境变量:
export LIBCLANG_PATH=/usr/lib/llvm-14/lib cargo build --release
内容的提问来源于stack exchange,提问作者Arek63

