从源码编译软件和打包软件

从源码编译软件实战

参照学习贴https://bbs.deepin.org/post/283392

学习平台:OpenEuler的WSL子系统
图片

1
2
3
# 安装需要的依赖
sudo dnf install gcc g++ make
# 下面还会报错可以把autoreconf、automake、ncurses-devel也提前安装

源码文档中的README.md文档会有一些说明,建议提前看哈
图片

1
2
3
4
5
6
7
# 切换到root用户
sudo su
# OpenEuler没有wget,要先安装
dnf install wget
# 下载源码,我这里用
wget https://github.com/htop-dev/htop/archive/refs/tags/3.2.2.tar.gz
# 我的所在目录是/home/brian/

图片
下载地址是:https://github.com/htop-dev/htop/releases

1
2
# 下载下来的文件解压出来
tar -xvzf 3.2.2.tar.gz

图片

1
2
# cd进去看看都有啥
cd htop-3.2.2

图片

下面所有的操作都是在/home/brian/htop-3.2.2/的目录下操作

1
2
3
# 执行这个脚本
./autogen.sh
# 如果遇到下面的1和2报错,安装对应确实软件即可,我也是问AI告诉我怎样解决的

错误1:./autogen.sh: line 2: autoreconf: command not found
如果遇到这个错误,请安装autoreconf

1
dnf install autoconf

图片
错误2:Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 274. autoreconf: error: aclocal failed with exit status: 2
如果遇到这个错误,请安装automake

1
dnf install automake

图片
再次执行./autogen.sh就能成功了

1
2
3
# 做环境配置,安装在/usr/local目录
./configure --prefix=/usr/local
# 如果遇到下面的3报错,安装对应确实软件即可,我也是问AI告诉我怎样解决的

错误3:configure: error: can not find required library libncursesw; you may want to use --disable-unicode
如果遇到这个错误,请安装ncurses-devel

1
dnf install ncurses-devel

图片
再次执行./configure --prefix=/usr/local就能成功了
图片

1
2
# 编译
make

图片

1
2
# 编译
sudo make install

图片

1
2
# 看看版本是否安装成功
htop --version

图片

1
2
# 执行命令看看是否成功
htop

图片

从源码打包deb包(没成功)

测试环境:Ubuntu 22.04 LTS 虚拟机
很多的步骤跟上面的差不多

1
2
3
4
sudo su #切换到root用户
sudo apt update #更新软件列表
# 安装必要软件
sudo apt install build-essential checkinstall devscripts dh-make fakeroot

图片
下载并解压htop

1
2
3
wget https://github.com/htop-dev/htop/archive/refs/tags/3.2.2.tar.gz
tar -xvzf 3.2.2.tar.gz
cd htop-3.2.2

图片
执行脚本

1
./autogen.sh

图片
执行环境配置

1
./configure

报错1:configure: error: can not find required library libncursesw; you may want to use --disable-unicode
安装libncursesw5-dev可以解决

1
apt install libncursesw5-dev

图片
再次执行./configure就能成功了
图片
开始打包

1
sudo checkinstall
  • 选择y用默认方法创建包
  • 写一段包的描述,这里我不知道怎样完成退出,用Ctrl + C退出了,需要再次运行sudo checkinstall继续打包
    图片
  • 这1-15的配置都是默认,回车就下一步
    图片
  • 这两个问题我应该把它们排除在包外么?不知道怎样选,感觉都选错了,才导致后面包无法用。
    图片
  • 包是生成了htop_3.2.2-1_amd64.deb
    图片
  • 安装了也无法运行,坑就踩到这里,后续研究出来再更新本文。
    图片