下面是对 Linux 中非常常用的源码编译三步命令:
./configure、make、make install 的详细讲解,适用于编译大多数从源码包安装的软件(如 .tar.gz):
很多 Linux 软件提供的是源代码包(如 .tar.gz),需要我们手动编译生成可执行文件。而这三步命令正是:
命令 | 作用 |
|---|---|
./configure | 配置编译参数和环境检测 |
make | 编译生成可执行文件或库 |
make install | 安装到系统指定目录(如 /usr/local/) |
./configure —— 配置阶段make 编译)configure 脚本一般是 GNU Autotools 自动生成的./configure --prefix=/usr/local/xxx --enable-xxx --disable-yyyphp62 Bytes© 菜鸟-创作你的创作参数 | 说明 |
|---|---|
--prefix | 指定安装路径,默认是 /usr/local |
--enable-xxx | 启用某个模块或功能 |
--disable-xxx | 禁用某个模块或功能 |
💡 示例:
./configure --prefix=/opt/nginx --with-http_ssl_modulephp54 Bytes© 菜鸟-创作你的创作make —— 编译阶段Makefile 文件,把源码编译为目标文件(如 .o)、可执行文件或动态库💡 示例输出:
gcc -o main.o -c main.cgcc -o myapp main.o util.ophp50 Bytes© 菜鸟-创作你的创作make install —— 安装阶段/usr/local/bin)sudo 提权:sudo make installphp17 Bytes© 菜鸟-创作你的创作.h).so)tar -zxvf nginx-1.20.2.tar.gzcd nginx-1.20.2./configure --prefix=/opt/nginxmakesudo make installphp100 Bytes© 菜鸟-创作你的创作命令 | 作用 |
|---|---|
make clean | 删除上次编译生成的中间文件(.o、.out) |
make uninstall | 若 Makefile 提供该目标,可执行卸载操作 |
make -j4 | 开启多线程并行编译,速度更快(如 -j4 表示使用4线程) |
错误 | 原因 | 解决方式 |
|---|---|---|
configure: command not found | 缺少 autoconf 工具 | sudo apt install autoconf |
No C compiler found | 系统未安装编译器 | 安装 gcc:sudo apt install build-essential |
Permission denied | 没有权限写入系统目录 | 用 sudo |
./configure # 配好环境make # 编译成品make install # 安装归位php62 Bytes© 菜鸟-创作你的创作
https://www.52runoob.com/archives/5353
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。