BC-Linux上安裝re2c
我在安裝 ninja 軟件包時遇到一個問題框冀,如下所示:
warning: A compatible version of re2c (>= 0.15.3) was not found; changes to src/.in.cc will not affect your build*.
這里提示 re2c 沒有找到,查閱了一下敏簿,re2c 是一個將正則表達式轉化成基于 C 語言標識的預處理器明也。于是想著從 github 上安裝一下這個軟件包。過程中碰到一些問題惯裕,所以想記錄一下分享出來温数。
從GitHub上下載 re2c 項目源碼
-
在 GitHub 上搜索 re2c
在GitHub上搜索re2c項目 -
找到最新版releases版本源碼
點擊Releases進入 -
下載項目源碼
下載最新的項目源碼壓縮包
編譯和安裝
- 將下載好的壓縮包放到 Linux 服務器上,我這里放到了 /home/share/ 目錄下蜻势,然后解壓
解壓命令:tar -xvzf re2c-3.0.tar.gz
[root@localhost share]# ls -d re2c*
re2c-3.0 re2c-3.0.tar.gz
[root@localhost share]#
可以看到已經將文件解壓到了 re2c-3.0 文件夾中了撑刺。
- 進入 re2c-3.0 目錄查看
[root@localhost share]# cd re2c-3.0/
[root@localhost re2c-3.0]# ls
add-release.txt build CMakeLists.txt doc lib Makefile.am release.sh test
autogen.sh BUILD.md CMakePresets.json examples libre2c_old Makefile.lib.am run_tests.py.in
benchmarks CHANGELOG configure.ac fuzz LICENSE NO_WARRANTY sf-cheatsheet
bootstrap cmake CONTRIBUTING.md include m4 README.md src
[root@localhost re2c-3.0]#
查看后發(fā)現沒有 configure 配置文件,此時我們運行 autogen.sh 腳本來生成 configure文件握玛。
- 運行 autogen.sh
[root@localhost re2c-3.0]# ./autogen.sh
fatal: Not a git repository (or any of the parent directories): .git
./autogen.sh: line 5: autoreconf: command not found
[root@localhost re2c-3.0]#
這里有一個 fatal 的錯誤提示說:當前的目錄不是一個 git 倉庫够傍。這個錯誤其實不影響編譯。為了不顯示這個錯誤挠铲,保證安裝的順利冕屯,我們可以在本地創(chuàng)建一個 git 倉庫,然后將解壓的 re2c-3.0 解壓文件夾拷貝到git倉庫目錄下拂苹,再執(zhí)行 autogen.sh 腳本文件安聘。
[root@localhost share]# git init github_re2c
Initialized empty Git repository in /home/share/github_re2c/.git/
[root@localhost share]# cd github_re2c/
[root@localhost github_re2c]# cp ../re2c-3.0.tar.gz ./
[root@localhost github_re2c]# ls
re2c-3.0.tar.gz
[root@localhost github_re2c]# tar -xvzf re2c-3.0.tar.gz
>>>>>>>>>>>>>> 中間的解壓過程省略 <<<<<<<<<<<<<<
[root@localhost github_re2c]#
[root@localhost github_re2c]# ls
re2c-3.0 re2c-3.0.tar.gz
[root@localhost github_re2c]# cd re2c-3.0/
[root@localhost re2c-3.0]# ls
add-release.txt build CMakeLists.txt doc lib Makefile.lib.am run_tests.py.in
autogen.sh BUILD.md CMakePresets.json examples libre2c_old NO_WARRANTY sf-cheatsheet
benchmarks CHANGELOG configure.ac fuzz LICENSE README.md src
bootstrap cmake CONTRIBUTING.md include Makefile.am release.sh test
[root@localhost re2c-3.0]#
[root@localhost re2c-3.0]# ./autogen.sh
./autogen.sh: line 5: autoreconf: command not found
[root@localhost re2c-3.0]#
這樣就不會報上面的錯誤了。此時提示 autoreconf: command not found,這是由于沒有安裝 autoconf 軟件包導致的搞挣。
- 安裝 autoconf
[root@localhost re2c-3.0]# yum install autoconf
Configuration file /etc/yum/pluginconf.d/license-manager.conf not found
Unable to find configuration file for plugin license-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
Installed:
autoconf.noarch 0:2.69-11.el7
Dependency Installed:
m4.x86_64 0:1.4.16-10.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7
Complete!
[root@localhost re2c-3.0]#
- 再次運行 autogen.sh
[root@localhost re2c-3.0]# ./autogen.sh
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory
[root@localhost re2c-3.0]#
此時又提示 Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.带迟,這是由于沒有安裝 automake 軟件包導致的
- 安裝 automake
[root@localhost re2c-3.0]# yum install automake
Configuration file /etc/yum/pluginconf.d/license-manager.conf not found
Unable to find configuration file for plugin license-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
Installed:
automake.noarch 0:1.13.4-3.el7
Dependency Installed:
perl-Test-Harness.noarch 0:3.28-3.el7
Complete!
[root@localhost re2c-3.0]#
- 三次運行 autogen.sh
[root@localhost re2c-3.0]# ./autogen.sh
configure.ac:3: installing 'build-aux/install-sh'
configure.ac:3: installing 'build-aux/missing'
Makefile.am:515: error: Libtool library used but 'LIBTOOL' is undefined
Makefile.am:515: The usual way to define 'LIBTOOL' is to add 'LT_INIT'
Makefile.am:515: to 'configure.ac' and run 'aclocal' and 'autoconf' again.
Makefile.am:515: If 'LT_INIT' is in 'configure.ac', make sure
Makefile.am:515: its definition is in aclocal's search path.
Makefile.am: installing 'build-aux/depcomp'
parallel-tests: installing 'build-aux/test-driver'
autoreconf: automake failed with exit status: 1
[root@localhost re2c-3.0]#
又出現一個錯誤:Makefile.am:515: error: Libtool library used but 'LIBTOOL' is undefined,這是由于沒有安裝 libtool 導致的囱桨。
- 安裝 libtool
[root@localhost re2c-3.0]# yum install libtool
Configuration file /etc/yum/pluginconf.d/license-manager.conf not found
Unable to find configuration file for plugin license-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package libtool.x86_64 0:2.4.2-22.el7_3 will be installed
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
Installed:
libtool.x86_64 0:2.4.2-22.el7_3
Complete!
[root@localhost re2c-3.0]#
- 四次運行 autogen.sh
[root@localhost re2c-3.0]# ./autogen.sh
Removing aclocal.m4
Removing config.h.in
Removing configure
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'.
libtoolize: copying file `build-aux/ltmain.sh'
libtoolize: putting macros in `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
configure.ac:191: installing 'build-aux/config.guess'
configure.ac:191: installing 'build-aux/config.sub'
[root@localhost re2c-3.0]#
到這里終于運行成功了仓犬,查看目錄下生成了 configure 文件。
[root@localhost re2c-3.0]# ls
aclocal.m4 bootstrap cmake configure.ac include Makefile.am release.sh
add-release.txt build CMakeLists.txt CONTRIBUTING.md lib Makefile.in run_tests.py.in
autogen.sh build-aux CMakePresets.json doc libre2c_old Makefile.lib.am sf-cheatsheet
autom4te.cache BUILD.md config.h.in examples LICENSE NO_WARRANTY src
benchmarks CHANGELOG configure fuzz m4 README.md test
[root@localhost re2c-3.0]#
- 運行 configure 配置文件
[root@localhost re2c-3.0]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
[root@localhost re2c-3.0]#
執(zhí)行完之后舍肠,查看目錄搀继,已經生成了 Makefile 文件
[root@localhost re2c-3.0]# ls
aclocal.m4 build-aux config.h.in examples m4 release.sh
add-release.txt BUILD.md config.log fuzz Makefile run_tests.py
autogen.sh CHANGELOG config.status include Makefile.am run_tests.py.in
autom4te.cache cmake configure lib Makefile.in sf-cheatsheet
benchmarks CMakeLists.txt configure.ac libre2c_old Makefile.lib.am src
bootstrap CMakePresets.json CONTRIBUTING.md libtool NO_WARRANTY stamp-h1
build config.h doc LICENSE README.md test
[root@localhost re2c-3.0]#
執(zhí)行 make 和 make install 命令進行編譯和安裝
此處編譯和安裝日志較多,所以不在累贅寫出翠语。查看安裝版本
[root@localhost re2c-3.0]# re2c -version
re2c 3.0
[root@localhost re2c-3.0]#
安裝好之后查看版本叽躯,顯示安裝的是 re2c 3.0 版本,說明安裝已經成功肌括。
從 EPEL 中安裝 re2c
安裝 re2c 還有另外一種方式点骑,那就是從 EPEL 中直接安裝,最為方便快捷谍夭,一般都能滿足要求黑滴,但不是最新的版本。
安裝步驟分兩步:
- 安裝軟件擴展包 EPEL
- 安裝 re2c
1. 安裝 EPEL
EPEL 的安裝請參考文章《Linux上安裝EPEL擴展包》紧索,這里不再講述袁辈。
2. 安裝 re2c
命令:yum install re2c
[root@localhost ~]# yum install re2c
Extra Packages for Enterprise Linux 7 - x86_64 14 kB/s | 17 MB 20:50
Last metadata expiration check: 0:10:35 ago on Sun 05 Mar 2023 06:49:56 PM EST.
Dependencies resolved.
===================================================================================================
Package Architecture Version Repository Size
===================================================================================================
Installing:
re2c x86_64 0.14.3-2.el7 epel 230 k
>>>>>>>>>>>>>> 中間的安裝過程省略 <<<<<<<<<<<<<<
Installed:
re2c-0.14.3-2.el7.x86_64
Complete!
[root@localhost ~]#
查看安裝版本
[root@localhost code]# re2c -version
re2c 0.14.3
[root@localhost code]#
4. 總結
編譯和安裝的依賴項
- 依賴項:git、autoconf珠漂、automake晚缩、libtool。git 本地倉庫的新建媳危,所有的操作在本地倉庫目錄下進行荞彼。
- 安裝 epel,然后從 epel 中安裝 re2c