源代码编译的三部曲
- 配置安装环境
- 编译源代码
- 将编译好的可执行文件安装到目标文件夹
安装zlib
vip39@VM-0-15-ubuntu:~$ cd src
vip39@VM-0-15-ubuntu:~/src$ wget http://zlib.net/zlib-1.2.11.tar.gz
vip39@VM-0-15-ubuntu:~/src$ tar xf zlib-1.2.11.tar.gz
vip39@VM-0-15-ubuntu:~/src$ cd zlib-1.2.11/
# --prefix 用于指定安装路径
# ./configure 表示运行当前路径下的configure程序
vip39@VM-0-15-ubuntu:~/src/zlib-1.2.11$ ./configure --prefix=$HOME/opt/sysoft
# 对程序进行编译
make 命令
# make install 执行第三步,将文件安装到指定到目标文件夹(--prefix指定文件)
tree
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ ls
CHANGES LICENSE README color.c file.c html.c strverscmp.c tree.h xml.c
INSTALL Makefile TODO doc hash.c json.c tree.c unix.c
# ./configure 表示运行当前路径下的configure程序
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ ./configure
-bash: ./configure: No such file or directory
# 但是./configure不能运行
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ less INSTALL
Installation instructions:
1. Edit the Makefile for your OS. Comment out the Linux options and un-comment
the options for your OS.
2. Type: make
3. Type: make install
4. Enjoy colorful directory trees.
...
# 第一步可以不管
# 第二步make
# 第三步make install
# 运行第三步
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ make install
install -d /usr/bin
install -d /usr/man/man1
install: cannot create directory '/usr/man': Permission denied
Makefile:112: recipe for target 'install' failed
make: *** [install] Error 1
# 没有权限,可以用prefix指定安装路径
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ make install prefix=/home/vip39/opt/sysoft
install -d /home/vip39/opt/sysoft/bin
install -d /home/vip39/opt/sysoft/man/man1
if [ -e tree ]; then \
install tree /home/vip39/opt/sysoft/bin/tree; \
fi
install doc/tree.1 /home/vip39/opt/sysoft/man/man1/tree.1
# 运行程序
# 绝对路径方式
vip39@VM-0-15-ubuntu:~/src/tree-1.8.0$ ~/opt/sysoft/bin/tree
vip39@VM-0-15-ubuntu:~$ which tree
/usr/bin/tree
vip39@VM-0-15-ubuntu:~$ vim ~/.bashrc
vip39@VM-0-15-ubuntu:~$ cat ~/.bashrc
export PATH=$PATH:~/opt/biosoft/ncbi-blast-2.7.1+/bin/:~/opt/sysoft/bin/tree
问题解决configure
- 为什么要在make install 增加prefix,为什么有些需要有些不需要
- 首先,试试不configure,直接make会发生什么?
# 首先删除编译好的zlib
vip39@VM-0-15-ubuntu:~/src$ rm -rf zlib-1.2.11
# 重新解压缩
vip39@VM-0-15-ubuntu:~/src$ cd zlib-1.2.11/
vip39@VM-0-15-ubuntu:~/src/zlib-1.2.11$ ls
CMakeLists.txt crc32.c inffast.c qnx zlib.3.pdf
ChangeLog crc32.h inffast.h test zlib.h
FAQ deflate.c inffixed.h treebuild.xml zlib.map
INDEX deflate.h inflate.c trees.c zlib.pc.cmakein
Makefile doc inflate.h trees.h zlib.pc.in
Makefile.in examples inftrees.c uncompr.c zlib2ansi
README gzclose.c inftrees.h watcom zutil.c
adler32.c gzguts.h make_vms.com win32 zutil.h
amiga gzlib.c msdos zconf.h
compress.c gzread.c nintendods zconf.h.cmakein
configure gzwrite.c old zconf.h.in
contrib infback.c os400 zlib.3
vip39@VM-0-15-ubuntu:~/src/zlib-1.2.11$ make
Please use ./configure first. Thank you.
- 不configure,直接make会发生:makefile没有配置,找不到makefile
- configure作用:检查系统,构建Makefile
网友评论