微信上跳出新闻,rust开发的zed编辑器速度非常快,比vscode体验好很多,处于对rust的好奇,在机器上安装,最终折腾一通失败了,记录一下,对在linux安装经验也是一个总结。另外也说明开源生态下,松散联盟,各种开源软件版本配合确实是个问题。爱折腾的人士才适合。
先总结一下:
1.下载受阻,curl 命令报:routines:ssl3_get_record:wrong version number,多次修改参数未果,经过后面的折腾莫名好了。最终也不知道怎么好的。
2.改为手工下载软件,运行提示 version `GLIBC_2.29' not found (required by ./zed),我用的是glibc2.28,正巧差一个版本,glibc是linux基础库,试了不能升级(公司内部版本,ubuntu估计是可以的)
3.按zed提示,源码安装,恰好前期安装了rust,直接安装。cargo run,提示缺少mold,这个不知是啥,查了一下是个优化的链接工具。
4.安装mold,提示#include <bit>找不到,核对后发现C++20的库,我的gcc太低不支持。我的GCC是8.4.1,升级gcc
5. 升级gcc. 既然升级就升级个最高版本14.2.0,提示缺少libmpfr.so.6
6.安装libmpfr.so.6,重新编译gcc,提示缺少3个库configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
7.安装三个库,套路相同:GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
8.重新编译gcc,发现gcc编译真是个浩大工程,不断提示文本文件忙,这是不要以为错误了,是编译器本身有问题,重新make就过了。估计重复Make十几次。最终成功。
9. 搞到这里几乎已经忘记为啥做这些事情了。回到开头,mold问题解决了,继续cargo run,提示错误变化了:mold: fatal: cannot open crtbeginS.o: No such file or directory. 这是切换gcc造成的,实验了好多办法误解。(原来的gcc不管替换,新gcc在新目录,反复设置环境变量无果)
10. 又回到非源码安装,看能否安装一个glibc2.29,不做替换,只是zed程序使用行不行
11. 安装glibc2.29,反复编译出错,最终原因竟然是必须在/tmp下运行才能成功,正常目录就出错,这也是个奇葩原因。编译通过后,zed还是不可用,应该是和glibc2.28冲突了,又不能更换,只能放弃。
总结:zed没有跑起来。学会了安装gcc, glibc两个基础库,但是学会了也不能用啊。基础库替换,还是要靠操作系统统一升级,有人把配套软件的版本对齐,我们做应用层的,尽量不折腾。用vscode也挺好。
下面把相关命令详细总结一下:
下载zed
Zed - The editor for what's next
页面提示运行命令:
curl -f https://zed.dev/install.sh | sh
报错:
curl: (35) OpenSSL/3.0.10: error:0A00010B:SSL routines::wrong version number
是不是内部运行没有设置proxy?
curl -x https://proxy.xxx:80 -f https://zed.dev/install.sh | sh
同样错误。
是不是没有设置tls版本?
curl --ssl -version TLSv1.2 -f https://zed.dev/install.sh | sh
同样错误。
最终放弃,最后莫名好了,不知原因。
直接ftp下载
mkdir -p ~/.local
# extract zed to ~/.local/zed.app/
tar -xvf <path/to/download>.tar.gz -C ~/.local
# link the zed binary to ~/.local/bin (or another directory in your $PATH)
ln -sf ~/.local/zed.app/bin/zed ~/.local/bin/zed
直接运行,提示:
/zed: /lib64/libc.so.6: version `GLIBC_2.29' not found (required by ./zed)
源码安装
rustup update
出错,加代理,加rust国内库
export https_proxy=proxy.xxx:80
export http_proxy=proxy.xxx:80
export RUSTUP_DIST_SERVER=https://mirrors.sjtug.sjtu.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.sjtug.sjtu.edu.cn/rust-static/rustup
rustup update
第一次运行,提示网络错误,再运行success,网络不靠谱。
克隆zed
git clone https://github.com/zed-industries/zed.git
这次倒是很顺利。
cargo run
cargo run -p cli
clang-11: error: invalid linker name in argument '-fuse-ld=mold'
mold是啥?网上搜:
https://github.com/rui314/mold
没办法,继续克隆编译
install mold
git clone https://github.com/rui314/mold.git
mkdir mold/build
cd mold/build
git checkout v2.0.0
../install-build-deps.sh
zed/mold/mold/common/integers.h:23:10: 致命错误:bit:没有那个文件或目录 #include <bit>
https://en.cppreference.com/w/cpp/header/bit
C++ 20才开始支持。
$ gcc --version
gcc (GCC) 8.4.1 20200928 (NewStart 8.4.1-1)
gcc版本太低,更新版本。
安装gcc是个大工程,查了一堆
https://ftp.gnu.org/gnu/gcc/gcc-14.2.0/
https://gcc.gnu.org/install/configure.html
https://gcc.gnu.org/wiki/InstallingGCC
https://blog.csdn.net/yule/article/details/139500414
https://www.cnblogs.com/zhongqifeng/p/18285116#:~:text=Install%20gcc-14%20on%20Ubuntu%2022.04%20The%20steps%3A%201,http%3A%20%2F%2Fftp.gnu.org%2Fgnu%2Fgcc%2Fgcc-14.1.0%2Fgcc-14.1.0.tar.gz%204%20tar%20-xf%20gcc%20-%2014.1.
https://osfere.com/linux/how-to-build-and-install-latest-gcc
开始安装
install gcc 14
tar -xvf gcc-14.2.0.tar.gz -C ~/.local
cd gcc-14.2.0/
mkdir objdir
cd objdir
../configure --prefix=/usr/local/gcc
../configure --prefix=/usr/local/gcc-14.2.0
../configure --prefix=/usr/local/gcc-14.2.0 --enable-languages=c,c++
error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory
libmpfr.so.6是啥?搜索:
https://pkgs.org/download/libmpfr6
http://mirror.yandex.ru/altlinux/Sisyphus/x86_64/RPMS.classic/libmpfr6-4.2.1-alt1.x86_64.rpm
https://www.cnblogs.com/a438842265/p/16282640.html
下载
rpm2cpio libmpfr6-4.1.0-alt2.x86_64.rpm | cpio -div
./usr/lib64/libmpfr.so.6
./usr/lib64/libmpfr.so.6.1.0
./usr/share/doc/mpfr-4.1.0
./usr/share/doc/mpfr-4.1.0/AUTHORS
./usr/share/doc/mpfr-4.1.0/BUGS
./usr/share/doc/mpfr-4.1.0/NEWS
5494 blocks
[root@localhost gcc_bag]# ls
libmpfr6-4.1.0-alt2.x86_64.rpm usr
[root@localhost gcc_bag]# mv ./usr/lib64/libmpfr.so.6 /usr/lib64/
[root@localhost gcc_bag]# mv ./usr/lib64/libmpfr.so.6.2.1 /usr/lib64/
继续configure
未生成Makefile
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
一下缺了三个软件,想放弃,搜了一下安装简单,继续吧:
https://www.cnblogs.com/zhiminyu/p/18267733 --重要参考
GMP编译:GMP 4.2+
下载地址:ftp://ftp.gnu.org/gnu/gmp/
https://gcc.gnu.org/pub/gcc/infrastructure/
gmp 6.2.1
tar -vxf gmp-6.2.1.tar.bz2 -C ~/.local
cd gmp-6.2.1/
./configure --prefix=/usr/local/gmp-6.2.1
make
sudo make install
configure: error: Oops, mp_limb_t doesn't seem to work
真是步步惊心,重新执行成功了。--说明编译又是不是命令的错误,只是莫名失败,要重试确认。
MPFR 3.1.0+
4.1.0
tar -vxf mpfr-4.1.0.tar.bz2 -C ~/.local
cd mpfr-4.1.0/
./configure --prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
make
sudo make install
MPC 0.8.0+
1.2.1
tar -vxf mpc-1.2.1.tar.gz -C ~/.local
cd mpc-1.2.1/
./configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
又是运行两次
make
sudo make install
gcc configure终于生成了Makefile,开始编译了。
然后就是10几次make,错误千篇一律,总是提示文本文件忙。我用的单线程,都没有启动并行编译。
成功后要切换到gcc新版本:
export CC=/usr/local/gcc-14.2.0/bin/gcc
export CXX=/usr/local/gcc-14.2.0/bin/g++
export LD_LIBRARY_PATH="/usr/local/gcc-14.2.0/lib64:$LD_LIBRARY_PATH"
export PATH="/usr/local/gcc-14.2.0/bin:$PATH"
重新编译安装mold
cmake --DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ ..
cmake --build . -j $(nproc)
sudo cmake -- install .
成功了。
重新编译zed
cargo run
-fuse-ld=mold
invalid linker name in argument '-fuse-ld=mold'
还是这个错误,应该是新编译的mold找不到,根据错误信息修改cargo配置文件
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=~/zed/mold/mold/build/mold"]
继续运行:
cargo run
cannot open crtbeginS.o: No such file or directory
cargo run -p cli
cannot open crtbeginS.o: No such file or directory
查这个文件
$ sudo find /usr/ -name crtbegin*
/usr/lib/gcc/x86_64-newstart-linux/8/32/crtbegin.o
/usr/lib/gcc/x86_64-newstart-linux/8/32/crtbeginS.o
/usr/lib/gcc/x86_64-newstart-linux/8/32/crtbeginT.o
/usr/lib/gcc/x86_64-newstart-linux/8/crtbegin.o
/usr/lib/gcc/x86_64-newstart-linux/8/crtbeginS.o
/usr/lib/gcc/x86_64-newstart-linux/8/crtbeginT.o
/usr/local/gcc-14.2.0/lib/gcc/x86_64-pc-linux-gnu/14.2.0/crtbegin.o
/usr/local/gcc-14.2.0/lib/gcc/x86_64-pc-linux-gnu/14.2.0/crtbeginS.o
/usr/local/gcc-14.2.0/lib/gcc/x86_64-pc-linux-gnu/14.2.0/crtbeginT.o
最后的gcc是新的,rust编译如何使用,不清楚,直接copy这个文件也不行。
export LIBRARY_PATH=/usr/local/gcc-14.2.0/lib/gcc/x86_64-pc-linux-gnu/14.2.0:$LIBRARY_PATH
export LIBRARY_PATH
cannot open crtbeginS.o: No such file or directory
export PATH="/usr/local/gcc-14.2.0/lib/gcc/x86_64-pc-linux-gnu/14.2.0:$PATH"
cannot open crtbeginS.o: No such file or directory
放弃。
重新试试最初的安装,莫名好了:
zed]$ curl -f https://zed.dev/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4327 100 4327 0 0 3417 0 0:00:01 0:00:01 --:--:-- 3417
Downloading Zed
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 565 100 565 0 0 261 0 0:00:02 0:00:02 --:--:-- 261
100 59.2M 100 59.2M 0 0 699k 0 0:01:26 0:01:26 --:--:-- 1119k
Zed has been installed. Run with 'zed'
再执行,还是提示:
$ zed
zed: /lib64/libc.so.6: version `GLIBC_2.29' not found (required by zed)
两招全不行:
https://zed.dev/docs/linux
Zed fails to start
If you see an error like "/lib64/libc.so.6: version 'GLIBC_2.29' not found" it means that your distribution's version of glibc is too old.
You can either upgrade your system, or install Zed from source.
https://zed.dev/docs/development/linux
note: mold: fatal: cannot open crtbeginS.o: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
放弃源码编译。走最后一招,安装GLIBC_2.29
里面好多版本,用2.29(后面的版本也不行,试过了)
下载tar
tar -xvf glibc-2.29.tar.gz -C ~/.local
cd glibc-2.29
mkdir build && cd build
../configure --prefix=/usr/local/glibc-2.29
提示:
LD_LIBRARY_PATH shouldn't contain the current directory when building glibc. Please change the environment variable
不得其解,终于搜到一个解释,需要情况LD环境变量
export LD_LIBRARY_PATH=
果然可以了,生成了Makefile
make
rtld-Rules:40: *** This makefile is a subroutine of elf/Makefile not to be used directly
难道这个版本不行,高了2.30,最高版本2.40,都报同样错误。奇怪。百思不得其解。
终于搜到一个人回答这个问题,要放到/tmp下编译,不太可能吧,有啥区别。最后实验了一下:
和上面步骤相同,编译成功了。
build]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/tmp/glibc-2.29/build
[root@LIN-93D422104AD build]# ~/.local/bin/zed
Inconsistency detected by ld.so: dl-call-libc-early-init.c: 37: _dl_call_libc_early_init: Assertion `sym != NULL' failed!
链接库不一致,有不能替换系统的库,只能放弃了。
至此, gcc版本,libc版本都替换了,但与系统运行版本不一致,无法替换,设置变量后也无法工作。安装zed以失败告终。总结经验就是不要自己折腾开源软件,版本匹配太难了。