一、本地编译安装步骤介绍
本地编译,指的是在本地环境编译安装某个软件,例如,本文所述的最新版postgis3.4.3,本地是什么cpu架构,编译完成后,编译产出物就可以在其它的同cpu架构的服务器上直接适用了,这里着重强调本地编译以区别于交叉编译
那么,回到开始的问题,本地编译最新版postgis3.4.3,这里的编译难点主要在于两点,第一个是编译环境的准备,第二个是编译的调试
编译环境,指的是能够使得编译工作完成的环境,主要就是安装各类依赖,例如,本文使用的最新版postgis3.4.3是基于c语言编写的,那么,编译环境就必须包含有各种各样的类库,比如gtk2-devel libxml2 libxml2-devel 这些类库,并且至少需要有一个gcc环境,并且这些类库以及gcc环境的版本可能都会有一定的要求,而版本依赖如何处理,如何使得这些安装的类库能够正常工作,这些问题使得编译环境的准备非常复杂,而本文将就这些困难的问题,做一个全面的解释,并指出一个可能更为高效,简洁的解决方案
编译调试,指的是从编译的错误处开始,直到消除所有的错误,最终完成编译的工作;很多同学拿到一个编译任务的时候,都只是简单的百度一下,然后根据各类教程进行编译活动,那么,其实我们的编译工作是应该有一个准确的良好的开端的,即编译工作到底应该从哪里开始,如何一步一步的把编译工作推进?
回到本文的最新版postgis3.4.3,我们拿到它的源码包后,应该是从哪里开始呢?当然了,首先第一步是阅读源码包内的说明文档,并根据文档内容,制定一个编译流程,然后开始我们的预编译工作,进而开始我们的编译工作和编译安装工作;那么,预编译如果报错了,我们应该如何做呢?当然是根据详细的报错信息,一步一步解决,这样的编译工作到最后都是自然的水到渠成的,能够顺利完成的
🆗,就不在这里废话了,下面以最新版postgis3.4.3在centos7的x86_64架构下如何一步步完成编译工作做一个简单的记录
二、最新版postgis3.4.3源码包的下载
下载地址:https://github.com/postgis/postgis/tags
或者在postgis的官网下载,下载地址:
Index of /postgis/source/
三、最新版postgis3.4.3源码包内的安装文档阅读
主要的安装文档是README.postgis,该文档里有详细介绍postgis的依赖情况,根据这个文档,做如下总结:
postgis-3.4.3安装
依赖如下:
1、GEOS - 3.12+ for ST_CoverageSimplify and ST_CoverageInvalidEdges- 3.11+ for improved ST_ConcaveHull, ST_lineMerge,and new functions ST_SimplifyPolygonHull, ST_TriangulatePolygon- 3.10+ for ST_MakeValid enhancements- 3.9+ is needed to take advantage offixed precision enhancements in overlay functions- 3.7+ is needed just for the ST_FrechetDistance function
最低版本是3.6,如果需要功能比较齐全,需要安装版本3.12 3..0.0用的是3.8.0版本,该版本需要高版本cmake编译,也就是使用cmake3,gcc版本至少需要72、 PROJ4
PROJ4 (Required, Version 6.1 or higher) 需要sqlite开发包,make编译比较慢,gcc7下通过
3、 protobuf
4、 protobuf-c-1.3.1,protobuf-c (Optional, Version 1.1.0 or higher)
现有的是protobuf-c-1.3.1,符合要求5、 gdal 这里使用高版本3.3.3,这个编译比较慢,GDAL
弱依赖,可以不安装,但建议安装,现有版本是gdal-2.1.3,建议安装3版本,该插件主要是启用光栅功能
6、 cgal
CGAL 4.1+ and SFCGAL 1.3.2+
高级3D共功能,建议安装
现有的是CGAL-4.13和SFCGAL-1.3.6,符合要求,SFCGAL 1.4.1+会支持更好
7、 sfcgal 8、libxml2[root@centos4 postgis-3.4.3]# rpm -qa |grep libxml
libxml2-2.9.1-6.el7.5.x86_64
libxml2-devel-2.9.1-6.el7.5.x86_64
需要版本2.5.0 ,现有仓库是2.9,可以直接rpm安装10、gettextrpm安装的是0.19.8.1
[root@centos4 postgis-3.4.3]# rpm -qa |grep gettext
gettext-0.19.8.1-3.el7.x86_64
gettext-libs-0.19.8.1-3.el7.x86_64图形化界面使用的,版本要求是0.14,现有仓库是0.19.8,可以直接rpm安装11、
JSON-C,现有版本未知,要求的是0.9及以上
在源码目录内可以看到,并没有configure.sh 这个预编译脚本,因此,需要安装autoconf和automake以生成configure.sh 这个预编译脚本,最终总结,应该使用yum安装如下依赖:
yum install automake autoconf gtk2 gtk2-devel libxml2 libxml2-devel xz xz-devel libtool autoconf automake gcc gcc-c++ make gettext sqlite sqlite-devel
四、根据最新版postgis3.4.3的安装文档确定编译工作中的各个依赖以及依赖如何处理
根据第三节所述,可以看到,我们需要的依赖GEOS PROJ4 protobuf protobuf-c gdal cgal sfcgal 这些需要特定版本,通常yum仓库内并没有现成的使用,因此,这些组件需要手动编译
而这些依赖安装还是有一定的顺序要求,因此,采用根据预编译日志来逐一处理的方式进行处理
下面将就在VMware 虚拟机 centos7操作系统,x86_64架构下编译最新版postgis3.4.3做一个详细的记录
五、最新版postgis3.4.3的预编译工作
1、将postgis3.4.3源码包上传到VMware虚拟机服务器后,解压待用
刚解压的源码包内发现是没有configure.sh 文件的,此时需要通过autogen.sh 脚本生成
2、
autogen.sh 脚本运行前的依赖安装
yum install automake autoconf gtk2 gtk2-devel libxml2 libxml2-devel xz xz-devel libtool autoconf automake gcc gcc-c++ make gettext sqlite sqlite-devel -y
3、
运行autogen.sh 脚本生成configure.sh 脚本
[root@centos4 postgis-3.4.3]# ./autogen.sh
* Running /usr/bin/libtoolize (2.4.2)OPTIONS = --force --copy --install
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build-aux'.
libtoolize: copying file `build-aux/config.guess'
libtoolize: copying file `build-aux/config.sub'
libtoolize: copying file `build-aux/install-sh'
libtoolize: copying file `build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `macros'.
libtoolize: copying file `macros/libtool.m4'
libtoolize: copying file `macros/ltoptions.m4'
libtoolize: copying file `macros/ltsugar.m4'
libtoolize: copying file `macros/ltversion.m4'
libtoolize: copying file `macros/lt~obsolete.m4'
libtoolize: Consider adding `-I macros' to ACLOCAL_AMFLAGS in Makefile.am.
* Running /usr/bin/aclocal (1.13.4)
* Running /usr/bin/autoconf (2.69)
======================================
Now you are ready to run './configure'
======================================
可以看到,autogen是依赖于libtool 这个依赖,以及依赖autoconf,aotomake 这两个依赖而运行的
4、
初次预编译
本次预编译肯定会报错,编译工作就是不停的试错
。。。。。。。。。。。。。。。省略
checking iconv.h usability... yes
checking iconv.h presence... yes
checking for iconv.h... yes
checking for libiconv_open in -liconv... no
checking for iconv_open in -lc... yes
checking for iconvctl... no
checking for libiconvctl... no
checking for pg_config... no
configure: error: could not find pg_config within the current path. You may need to re-run configure with a --with-pgconfig parameter.
。。。。。。。。结尾了
可以看到,首要依赖是postgresql数据库,解决方法很简单,先安装一个postgresql
yum install postgresql12-server-12.4 postgresql12-libs-12.4 postgresql12-devel-12.4 postgresql12-contrib-12.4 postgresql12-tcl postgresql12-odbc postgresql12-12.4 postgresql12-plperl-12.4 postgresql12-pltcl-12.4 postgresql12-plpython-12.4 postgresql12-plpython3-12.4 postgresql12-llvmjit-12.4 postgresql12-devel-12.4 -y
数据库安装完毕后,搜pg_config,找到该文件后,将预编译命令修改为如下:
[root@centos4 postgis-3.4.3]# find / -name pg_config
/usr/pgsql-12/bin/pg_config./configure --with-pgconfig=/usr/pgsql-12/bin/pg_config
预编译报错如下:
checking libxml/xpathInternals.h usability... yes
checking libxml/xpathInternals.h presence... yes
checking for libxml/xpathInternals.h... yes
checking for xmlInitParser in -lxml2... yes
checking for geos-config... no
configure: error: could not find geos-config within the current path. You may need to try re-running configure with a --with-geosconfig paramete
提示缺少geos这个依赖
5、
解决geos这个依赖
查询自建的yum仓库,可以看到有3.11版本的geos,但前面提到的文档说3.12的版本更好,因此,geos自编译
[root@centos4 postgis-3.4.3]# yum list |grep geos
Repository 'local' is missing name in configuration, using id
geos.x86_64 3.4.2-2.el7 epel_x86_64
geos-devel.x86_64 3.4.2-2.el7 epel_x86_64
geos-php.x86_64 3.4.2-2.el7 epel_x86_64
geos-python.x86_64 3.4.2-2.el7 epel_x86_64
geos310.x86_64 3.10.3-1.rhel7 pg_all
geos310-debuginfo.x86_64 3.10.3-1.rhel7 pg_all
geos310-devel.x86_64 3.10.3-1.rhel7 pg_all
geos311.x86_64 3.11.2-1.rhel7 pg_all
geos311-debuginfo.x86_64 3.11.2-1.rhel7 pg_all
geos311-devel.x86_64 3.11.2-1.rhel7 pg_all
geos37.x86_64 3.7.2-2.rhel7 pg_all
geos37-debuginfo.x86_64 3.7.2-2.rhel7 pg_all
geos37-devel.x86_64 3.7.2-2.rhel7 pg_all
geos38.x86_64 3.8.1-2.rhel7 pg_all
geos38-debuginfo.x86_64 3.8.1-2.rhel7 pg_all
geos38-devel.x86_64 3.8.1-2.rhel7 pg_all
geos39.x86_64 3.9.2-1.rhel7 pg_all
geos39-debuginfo.x86_64 3.9.2-1.rhel7 pg_all
geos39-devel.x86_64 3.9.2-1.rhel7 pg_all
从GitHub上下载geos-3.12.2.tar.bz这个文件,下载地址就不用说了,一搜就找到了,开始预编译geos:
root@centos4 ~]# tar xf geos-3.12.2.tar.bz2
[root@centos4 ~]# cd geos-3.12.2
[root@centos4 geos-3.12.2]# ./configure
You need cmake to build this package
🆗,这个geos高版本需要cmake编译器来编译,查询仓库可以看到有cmake3:
root@centos4 geos-3.12.2]# yum list |grep cmake
Repository 'local' is missing name in configuration, using id
cmake.x86_64 2.8.12.2-2.el7 base_x86_64
cmake-fedora.noarch 2.9.3-1.el7 epel_x86_64
cmake-gui.x86_64 2.8.12.2-2.el7 base_x86_64
cmake3.x86_64 3.17.5-1.el7 epel_x86_64
cmake3-data.noarch 3.17.5-1.el7 epel_x86_64
cmake3-doc.noarch 3.17.5-1.el7 epel_x86_64
cmake3-gui.x86_64 3.17.5-1.el7 epel_x86_64
extra-cmake-modules.noarch 5.52.0-1.el7 epel_x86_64
直接安装这个cmake3,版本3.17
yum install cmake3* -y
创建build目录,并进入build目录,开始编译geos:
[root@centos4 geos-3.12.2]# mkdir build
[root@centos4 geos-3.12.2]# cd build/
[root@centos4 build]# cmake3 ../
预编译通过后发现make有问题,make失败,失败日志如下:
[root@centos4 build]# make
Scanning dependencies of target ryu
[ 0%] Building C object src/deps/CMakeFiles/ryu.dir/ryu/d2s.c.o
[ 0%] Built target ryu
Scanning dependencies of target geos
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/Angle.cpp.o
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/Area.cpp.o
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/BoundaryNodeRule.cpp.o
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/CGAlgorithmsDD.cpp.o
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/Centroid.cpp.o
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/ConvexHull.cpp.o
In file included from /root/geos-3.12.2/src/algorithm/ConvexHull.cpp:30:0:
/root/geos-3.12.2/include/geos/util.h:38:12: error: ‘std::make_unique’ has not been declaredusing std::make_unique;^
/root/geos-3.12.2/src/algorithm/ConvexHull.cpp: In member function ‘std::unique_ptr<geos::geom::CoordinateSequence> geos::algorithm::ConvexHull::toCoordinateSequence(geos::geom::Coordinate::ConstVect&)’:
/root/geos-3.12.2/src/algorithm/ConvexHull.cpp:118:15: error: ‘make_unique’ is not a member of ‘geos::detail’auto cs = detail::make_unique<CoordinateSequence>(cv.size());^
/root/geos-3.12.2/src/algorithm/ConvexHull.cpp:118:53: error: expected primary-expression before ‘>’ tokenauto cs = detail::make_unique<CoordinateSequence>(cv.size());^
make[2]: *** [CMakeFiles/geos.dir/src/algorithm/ConvexHull.cpp.o] Error 1
make[1]: *** [CMakeFiles/geos.dir/all] Error 2
make: *** [all] Error 2
这里的错误的真实意思是gcc编译器找不到某个函数,而根本原因是gcc版本过低,是4.8.5,因此,升级gcc版本到7.3就可以解决此问题了(build目录需要清空,重新预编译一次,然后开始make和make install):
[root@centos4 build]# source /opt/rh/
devtoolset-7/ llvm-toolset-7/
[root@centos4 build]# source /opt/rh/devtoolset-7/enable
[root@centos4 build]# make
[ 0%] Built target ryu
[ 0%] Building CXX object CMakeFiles/geos.dir/src/algorithm/ConvexHull.cpp.o
In file included from /root/geos-3.12.2/src/algorithm/ConvexHull.cpp:30:0:
/root/geos-3.12.2/include/geos/util.h:38:12: error: ‘std::make_unique’ has not been declaredusing std::make_unique;
剩下的时候基本没有什么困难了,一路顺畅,geos安装完毕后,回到postgis目录下,继续预编译调试
6、再次预编译postgis
checking for CFPreferencesCopyAppValue... no
checking for CFLocaleCopyPreferredLanguages... no
checking for GNU gettext in libc... yes
checking whether to use NLS... yes
checking where the gettext function comes from... libc
checking for PROJ... no
checking proj_api.h usability... no
checking proj_api.h presence... no
checking for proj_api.h... no
checking proj.h usability... no
checking proj.h presence... no
checking for proj.h... no
configure: error: could not find proj.h or proj_api.h - you may need to specify the directory of a PROJ installation using --with-projdir
报错没有proj4,并且说明这个是强依赖,必须安装,可以看到yum仓库里有高版本的proj4
[root@centos4 postgis-3.4.3]# yum list |grep proj
Repository 'local' is missing name in configuration, using id
apache-james-project.noarch 1.8.1-14.el7 epel_x86_64
fedora-gnat-project-common.noarch 3.9-1.el7 epel_x86_64
geany-plugins-projectorganizer.x86_64 1.38-1.el7 epel_x86_64
httpcomponents-project.noarch 6-4.el7 base_x86_64
jetty-project.noarch 9.0.3-8.el7 base_x86_64
libprojectM.x86_64 2.1.0-2.el7 epel_x86_64
libprojectM-devel.x86_64 2.1.0-2.el7 epel_x86_64
libprojectM-qt.x86_64 2.1.0-2.el7 epel_x86_64
libprojectM-qt-devel.x86_64 2.1.0-2.el7 epel_x86_64
maven-project.noarch 2.2.1-47.el7 base_x86_64
maven-project-info-reports-plugin.noarch 2.6-8.el7 base_x86_64
maven-project-info-reports-plugin-javadoc.noarch
pjproject.x86_64 2.3-6.el7 epel_x86_64
pjproject-devel.x86_64 2.3-6.el7 epel_x86_64
proj.x86_64 4.8.0-4.el7 epel_x86_64
proj-devel.x86_64 4.8.0-4.el7 epel_x86_64
proj-epsg.x86_64 4.8.0-4.el7 epel_x86_64
proj-nad.x86_64 4.8.0-4.el7 epel_x86_64
proj-static.x86_64 4.8.0-4.el7 epel_x86_64
proj49.x86_64 4.9.3-3.rhel7 pg_all
proj49-debuginfo.x86_64 4.9.3-3.rhel7 pg_all
proj49-devel.x86_64 4.9.3-3.rhel7 pg_all
proj49-epsg.x86_64 4.9.3-3.rhel7 pg_all
proj49-nad.x86_64 4.9.3-3.rhel7 pg_all
proj49-static.x86_64 4.9.3-3.rhel7 pg_all
proj62.x86_64 6.2.1-1.rhel7 pg_all
proj62-debuginfo.x86_64 6.2.1-1.rhel7 pg_all
proj62-devel.x86_64 6.2.1-1.rhel7 pg_all
proj62-static.x86_64 6.2.1-1.rhel7 pg_all
proj63.x86_64 6.3.1-1.rhel7 pg_all
proj63-debuginfo.x86_64 6.3.1-1.rhel7 pg_all
proj63-devel.x86_64 6.3.1-1.rhel7 pg_all
proj63-static.x86_64 6.3.1-1.rhel7 pg_all
proj70.x86_64 7.0.1-4.rhel7 pg_all
proj70-debuginfo.x86_64 7.0.1-4.rhel7 pg_all
proj70-devel.x86_64 7.0.1-4.rhel7 pg_all
proj70-static.x86_64 7.0.1-4.rhel7 pg_all
proj71.x86_64 7.1.1-3.rhel7 pg_all
proj71-debuginfo.x86_64 7.1.1-3.rhel7 pg_all
proj71-devel.x86_64 7.1.1-3.rhel7 pg_all
proj71-static.x86_64 7.1.1-3.rhel7 pg_all
proj72.x86_64 7.2.1-1.rhel7 pg_all
proj72-debuginfo.x86_64 7.2.1-1.rhel7 pg_all
proj72-devel.x86_64 7.2.1-1.rhel7 pg_all
proj72-static.x86_64 7.2.1-1.rhel7 pg_all
proj80.x86_64 8.0.1-1.rhel7 pg_all
proj80-debuginfo.x86_64 8.0.1-1.rhel7 pg_all
proj80-devel.x86_64 8.0.1-1.rhel7 pg_all
proj80-static.x86_64 8.0.1-1.rhel7 pg_all
proj81.x86_64 8.1.1-1.rhel7 pg_all
proj81-debuginfo.x86_64 8.1.1-1.rhel7 pg_all
proj81-devel.x86_64 8.1.1-1.rhel7 pg_all
proj81-static.x86_64 8.1.1-1.rhel7 pg_all
因此,使用yum来处理这个依赖:
yum install proj63* -y
yum安装完毕后,postgis的预编译命令又需要更改了:
./configure --with-pgconfig=/usr/pgsql-12/bin/pg_config --with-projdir=/usr/proj63/
上面这个命令输出如下:
checking whether to use NLS... yes
checking where the gettext function comes from... libc
Using user-specified proj directory: /usr/proj63/
checking proj_api.h usability... no
checking proj_api.h presence... no
checking for proj_api.h... no
checking proj.h usability... yes
checking proj.h presence... yes
checking for proj.h... yes
checking for proj.h... (cached) yes
checking for pj_get_release in -lproj... yes
checking for JSONC... no
configure: WARNING: "Could not find json-c"
checking for PROTOBUFC... no
libprotobuf-c not found in pkg-config
checking protobuf-c/protobuf-c.h usability... no
checking protobuf-c/protobuf-c.h presence... no
checking for protobuf-c/protobuf-c.h... no
configure: error: unable to find protobuf-c/protobuf-c.h using CPPFLAGS. You can disable MVT and Geobuf support using --without-protobuf
可以看到,proj4已经通过,但protobuf-c 这个强依赖没有通过,因为还没安装,下面处理protobuf-c
7、protobuf-c的安装
protobuf和protobuf-c互为依赖
protobuf的安装
cd protobuf-2.6.1
./configure --prefix=/usr/local/protobuf
make && make install
注意,要指定安装路径哦!!!
protobuf-c的安装
vim /etc/profile 在文件末尾添加如下内容:
export PROTOBUF_HOME=/usr/local/protobuf
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig
执行命令 source /etc/profile 激活环境变量
解压安装文件后,进入目录,并执行编译:
cd protobuf-c-1.3.1
./configure --prefix=/usr/local/protobuf-c
make && make install
注意,要指定安装路径哦!!
8、再次预编译postgis-3.4.3
此时日志报错如下;
checking for PROTOBUFC... no
libprotobuf-c not found in pkg-config
checking protobuf-c/protobuf-c.h usability... yes
checking protobuf-c/protobuf-c.h presence... yes
checking for protobuf-c/protobuf-c.h... yes
checking for protobuf_c_message_init in -lprotobuf-c... yes
checking for protobuf_c_version in -lprotobuf-c... yes
checking protobuf-c version... configure: error: "Old protobuf-c release found but 1.1.0 is required. You can disable MVT and Geobuf support using --without-protobuf"
解决方式为安装低版本的protobuf-c的开发库:
yum install protobuf-c*
Loaded plugins: fastestmirror
Repository 'local' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package protobuf-c.x86_64 0:1.0.2-3.el7 will be installed
---> Package protobuf-c-compiler.x86_64 0:1.0.2-3.el7 will be installed
--> Processing Dependency: libprotobuf.so.8()(64bit) for package: protobuf-c-compiler-1.0.2-3.el7.x86_64
---> Package protobuf-c-devel.x86_64 0:1.0.2-3.el7 will be installed
---> Package protobuf-compiler.x86_64 0:2.5.0-8.el7 will be installed
--> Running transaction check
---> Package protobuf.x86_64 0:2.5.0-8.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved==============================================================================================================================================================================================================================================================================================================================================Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================================================================================
Installing:protobuf-c x86_64 1.0.2-3.el7 base_x86_64 28 kprotobuf-c-compiler x86_64 1.0.2-3.el7 base_x86_64 80 kprotobuf-c-devel x86_64 1.0.2-3.el7 base_x86_64 14 kprotobuf-compiler x86_64 2.5.0-8.el7 base_x86_64 261 k
Installing for dependencies:protobuf x86_64 2.5.0-8.el7 base_x86_64 338 kTransaction Summary
==============================================================================================================================================================================================================================================================================================================================================
Install 4 Packages (+1 Dependent package)Total download size: 721 k
Installed size: 2.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): protobuf-c-1.0.2-3.el7.x86_64.rpm | 28 kB 00:00:00
(2/5): protobuf-c-compiler-1.0.2-3.el7.x86_64.rpm | 80 kB 00:00:00
(3/5): protobuf-2.5.0-8.el7.x86_64.rpm | 338 kB 00:00:00
(4/5): protobuf-c-devel-1.0.2-3.el7.x86_64.rpm | 14 kB 00:00:00
(5/5): protobuf-compiler-2.5.0-8.el7.x86_64.rpm | 261 kB 00:00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.8 MB/s | 721 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : protobuf-2.5.0-8.el7.x86_64 1/5 Installing : protobuf-c-1.0.2-3.el7.x86_64 2/5 Installing : protobuf-compiler-2.5.0-8.el7.x86_64 3/5 Installing : protobuf-c-compiler-1.0.2-3.el7.x86_64 4/5 Installing : protobuf-c-devel-1.0.2-3.el7.x86_64 5/5 Verifying : protobuf-compiler-2.5.0-8.el7.x86_64 1/5 Verifying : protobuf-c-compiler-1.0.2-3.el7.x86_64 2/5 Verifying : protobuf-c-1.0.2-3.el7.x86_64 3/5 Verifying : protobuf-c-devel-1.0.2-3.el7.x86_64 4/5 Verifying : protobuf-2.5.0-8.el7.x86_64 5/5 Installed:protobuf-c.x86_64 0:1.0.2-3.el7 protobuf-c-compiler.x86_64 0:1.0.2-3.el7 protobuf-c-devel.x86_64 0:1.0.2-3.el7 protobuf-compiler.x86_64 0:2.5.0-8.el7 Dependency Installed:protobuf.x86_64 0:2.5.0-8.el7 Complete!
9、再次编译postgis-3.4.3
可以看到protobuf-c的问题解决了,但json-c和gdal没有解决
checking for JSONC... no
configure: WARNING: "Could not find json-c"
checking for PROTOBUFC... no
libprotobuf-c not found in pkg-config
checking protobuf-c/protobuf-c.h usability... yes
checking protobuf-c/protobuf-c.h presence... yes
checking for protobuf-c/protobuf-c.h... yes
checking for protobuf_c_message_init in -lprotobuf-c... yes
checking for protobuf_c_version in -lprotobuf-c... yes
checking protobuf-c version... 1003001
checking for protoc-c... /usr/bin/protoc-c
checking if gcc supports -Wall... yes
phony-revision:
checking for PCRE2... no
checking for PCRE... yes
TOPOLOGY: Topology support requested
RASTER: Raster support requested
checking for gdal-config... no
checking GDAL version... not found
configure: error: gdal-config not found. Use --without-raster or try --with-gdalconfig=<path to gdal-config>
10、解决json-c的问题
[root@centos4 postgis-3.4.3]# yum list |grep json-c
Repository 'local' is missing name in configuration, using id
json-c.x86_64 0.11-4.el7_0 @anaconda
json-c.i686 0.11-4.el7_0 base_x86_64
json-c-devel.i686 0.11-4.el7_0 base_x86_64
json-c-devel.x86_64 0.11-4.el7_0 base_x86_64
json-c-doc.noarch 0.11-4.el7_0 base_x86_64
json-c12.x86_64 0.12.1-4.el7 epel_x86_64
json-c12-devel.x86_64 0.12.1-4.el7 epel_x86_64
json-c12-doc.noarch 0.12.1-4.el7 epel_x86_64
nodejs-strip-json-comments.noarch 1.0.2-2.el7 epel_x86_64
rh-nodejs6-nodejs-strip-json-comments.noarch
rh-nodejs8-nodejs-strip-json-comments.noarch
[root@centos4 postgis-3.4.3]# yum install json-c* -y
Loaded plugins: fastestmirror
Repository 'local' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
Package json-c-0.11-4.el7_0.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package json-c-devel.x86_64 0:0.11-4.el7_0 will be installed
---> Package json-c-doc.noarch 0:0.11-4.el7_0 will be installed
---> Package json-c12.x86_64 0:0.12.1-4.el7 will be installed
---> Package json-c12-devel.x86_64 0:0.12.1-4.el7 will be installed
---> Package json-c12-doc.noarch 0:0.12.1-4.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved==============================================================================================================================================================================================================================================================================================================================================Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================================================================================
Installing:json-c-devel x86_64 0.11-4.el7_0 base_x86_64 20 kjson-c-doc noarch 0.11-4.el7_0 base_x86_64 98 kjson-c12 x86_64 0.12.1-4.el7 epel_x86_64 24 kjson-c12-devel x86_64 0.12.1-4.el7 epel_x86_64 24 kjson-c12-doc noarch 0.12.1-4.el7 epel_x86_64 114 kTransaction Summary
==============================================================================================================================================================================================================================================================================================================================================
Install 5 PackagesTotal download size: 280 k
Installed size: 1.5 M
Downloading packages:
(1/5): json-c-doc-0.11-4.el7_0.noarch.rpm | 98 kB 00:00:00
(2/5): json-c-devel-0.11-4.el7_0.x86_64.rpm | 20 kB 00:00:00
(3/5): json-c12-devel-0.12.1-4.el7.x86_64.rpm | 24 kB 00:00:00
(4/5): json-c12-0.12.1-4.el7.x86_64.rpm | 24 kB 00:00:00
(5/5): json-c12-doc-0.12.1-4.el7.noarch.rpm | 114 kB 00:00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.4 MB/s | 280 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : json-c12-0.12.1-4.el7.x86_64 1/5 Installing : json-c12-devel-0.12.1-4.el7.x86_64 2/5 Installing : json-c-doc-0.11-4.el7_0.noarch 3/5 Installing : json-c12-doc-0.12.1-4.el7.noarch 4/5 Installing : json-c-devel-0.11-4.el7_0.x86_64 5/5 Verifying : json-c-devel-0.11-4.el7_0.x86_64 1/5 Verifying : json-c12-0.12.1-4.el7.x86_64 2/5 Verifying : json-c12-devel-0.12.1-4.el7.x86_64 3/5 Verifying : json-c12-doc-0.12.1-4.el7.noarch 4/5 Verifying : json-c-doc-0.11-4.el7_0.noarch 5/5 Installed:json-c-devel.x86_64 0:0.11-4.el7_0 json-c-doc.noarch 0:0.11-4.el7_0 json-c12.x86_64 0:0.12.1-4.el7 json-c12-devel.x86_64 0:0.12.1-4.el7 json-c12-doc.noarch 0:0.12.1-4.el7 Complete!
11、gdal的安装
根据最开始的文档,gdal需要使用高版本,刚好yum源里面有,但这里为了照顾很多不会配仓库的同学,这里还是编译安装gdal-3.3.3:
./configure --prefix=/usr/local/gdal --with-proj=/usr/proj63/
这里必须要指定--with-proj=/usr/proj63/ ,要不然找不到proj的类库,gdal安装比较费时间,大概半个多小时
12、再次预编译postgis-3.4.3
编译命令为:
./configure --with-pgconfig=/usr/pgsql-12/bin/pg_config --with-protobufdir=/usr/local/protobuf-c --with-gdalconfig=/usr/local/gdal/bin/gdal-config
日志为:
PostGIS is now configured for x86_64-unknown-linux-gnu-------------- Compiler Info ------------- C compiler: gcc -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -WallC++ compiler (Wagyu): gcc -std=gnu99 -std=c++11 -x c++ C++ compiler (FlatGeobuf): gcc -std=gnu99 -std=c++11 -x c++ CPPFLAGS: -I/usr/local/include -I/usr/proj63//include -I/usr/local/protobuf-c/include -I/usr/include/libxml2 -I/usr/include/json-c -DNDEBUG LDFLAGS: -lmSQL preprocessor: /opt/rh/devtoolset-7/root/usr/bin/cpp -traditional-cpp -w -P -Upixel -UboolArchiver: gcc-ar rs-------------- Additional Info ------------- Interrupt Tests: ENABLED-------------- Dependencies -------------- GEOS config: /usr/local/bin/geos-configGEOS version: 3.12.2GDAL config: /usr/local/gdal/bin/gdal-configGDAL version: 3.3.3PostgreSQL config: /usr/pgsql-12/bin/pg_configPostgreSQL version: PostgreSQL 12.4PROJ4 version: 63Libxml2 config: /usr/bin/xml2-configLibxml2 version: 2.9.1JSON-C support: yesprotobuf support: yesprotobuf-c version: 1003001PCRE support: Version 1Perl: /usr/bin/perl--------------- Extensions --------------- PostgreSQL EXTENSION support: enabledPostGIS Raster: enabledPostGIS Topology: enabledSFCGAL support: disabledAddress Standardizer support: enabled-------- Documentation Generation -------- xsltproc: /usr/bin/xsltprocxsl style sheets: dblatex: convert: mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtdconfigure: WARNING:
configure: WARNING: | You are building using --with-projdir. This option isn't standard and |
configure: WARNING: | might be incompatible with future releases of PROJ. |
configure: WARNING: | You can instead adjust the PKG_CONFIG_PATH environment variable if you |
configure: WARNING: | installed software in a non-standard prefix. |
configure: WARNING: | Alternatively, you may set the environment variables PROJ_CFLAGS and |
configure: WARNING: | PROJ_LIBS to avoid the need to call pkg-config. |
这里有一些告警,还是处理一些,告警说的是projdir是参数形式,这个不标准
export CPLUS_INCLUDE_PATH=/usr/proj63/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/proj63/lib:/usr/local/protobuf-c/lib:/usr/local/protobuf/lib:$LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/proj63/lib/pkgconfig:/usr/local/protobuf/lib/pkgconfig:/usr/local/protobuf-c/lib/pkgconfig:$PKG_CONFIG_PATH
再次执行编译,发现还缺少最后一个依赖SFCGAL
PostGIS is now configured for x86_64-unknown-linux-gnu-------------- Compiler Info ------------- C compiler: gcc -std=gnu99 -g -O2 -fno-math-errno -fno-signed-zeros -WallC++ compiler (Wagyu): gcc -std=gnu99 -std=c++11 -x c++ C++ compiler (FlatGeobuf): gcc -std=gnu99 -std=c++11 -x c++ CPPFLAGS: -I/usr/local/include -I/usr/local/protobuf-c/include -I/usr/include/libxml2 -I/usr/include/json-c -DNDEBUG LDFLAGS: -lmSQL preprocessor: /opt/rh/devtoolset-7/root/usr/bin/cpp -traditional-cpp -w -P -Upixel -UboolArchiver: gcc-ar rs-------------- Additional Info ------------- Interrupt Tests: ENABLED-------------- Dependencies -------------- GEOS config: /usr/local/bin/geos-configGEOS version: 3.12.2GDAL config: /usr/local/gdal/bin/gdal-configGDAL version: 3.3.3PostgreSQL config: /usr/pgsql-12/bin/pg_configPostgreSQL version: PostgreSQL 12.4PROJ4 version: 63Libxml2 config: /usr/bin/xml2-configLibxml2 version: 2.9.1JSON-C support: yesprotobuf support: yesprotobuf-c version: 1003001PCRE support: Version 1Perl: /usr/bin/perl--------------- Extensions --------------- PostgreSQL EXTENSION support: enabledPostGIS Raster: enabledPostGIS Topology: enabledSFCGAL support: disabledAddress Standardizer support: enabled-------- Documentation Generation -------- xsltproc: /usr/bin/xsltprocxsl style sheets: dblatex: convert: mathml2.dtd: http://www.w3.org/Math/DTD/mathml2/mathml2.dtd
13、cgal和sfcgal编译安装
cgal和sfcgal是一对依赖,必须先cgal然后sfcgal
cgal的安装cd cgal-releases-CGAL-4.13/
mkdir build
cd build
cmake3 ../
make &&make install
注意,这个不要尝试指定安装目录,一切默认即可!!!!#这里需要注意,有三个依赖要安装,gmp-devel mpfr-devel boost*
-- GMP has been preconfigured:
-- UseGMP-file:
-- GMP include: /usr/include
-- GMP libraries: /usr/lib64/libgmp.so
-- GMP definitions:
-- USING GMP_VERSION = '6.0.0'
-- Preconfiguring library: MPFR ...
-- Found MPFR: /usr/lib64/libmpfr.so
-- MPFR has been preconfigured:
-- UseMPFR-file:
-- MPFR include: /usr/include
-- MPFR libraries: /usr/lib64/libmpfr.so
-- MPFR definitions:
-- USING MPFR_VERSION = '3.1.1'
-- __cplusplus is 201402
-- --> Do not link with Boost.Thread
CMake Error at /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:164 (message):Could NOT find Boost (missing: Boost_INCLUDE_DIR) (Required is at leastversion "1.48")
Call Stack (most recent call first):/usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)/usr/share/cmake3/Modules/FindBoost.cmake:2166 (find_package_handle_standard_args)Installation/cmake/modules/CGAL_SetupBoost.cmake:50 (find_package)Installation/cmake/modules/CGAL_SetupDependencies.cmake:85 (include)Installation/CMakeLists.txt:673 (include)-- Configuring incomplete, errors occurred!
See also "/root/cgal-releases-CGAL-4.13/build/CMakeFiles/CMakeOutput.log".
boost需要版本1.48以上sfcgal的安装cd SFCGAL-1.3.6/
mkdir build
cd build
cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local/sfcgal ../
make &&make install
注意,要指定安装路径哦!!!不可以多线程!!!!!会报错
14、最后一次预编译postgis-3.4.3并执行编译和编译安装
在预编译前,有一个程序需要链接到系统环境内:
ln -sf /usr/local/protobuf-c/bin/protoc-c /usr/bin/
预编译命令如下:
./configure --with-pgconfig=/usr/pgsql-12/bin/pg_config --with-protobufdir=/usr/local/protobuf-c --with-gdalconfig=/usr/local/gdal/bin/gdal-config --with-sfcgal=/usr/local/sfcgal/bin/sfcgal-config --with-protobuf-lib=/usr/local/protobuf-c/lib/
在make前,还有两个lib库需要添加到ld里面
/usr/local/lib64/
/usr/local/sfcgal/lib64/
这些都做了后,make 和make install 一路顺畅
此时,可以进入启动的数据库内,激活插件了,但激活的时候遇到了这些问题:
postgres=# create extension postgis;
ERROR: extension "postgis" already exists
postgres=# create extension postgis_
postgis_raster postgis_sfcgal postgis_tiger_geocoder postgis_topology
postgres=# create extension postgis_raster ;
ERROR: could not load library "/usr/pgsql-12/lib/postgis_raster-3.so": libgdal.so.29: cannot open shared object file: No such file or directory
因此,ld里面在添加gdal的库:
cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib64/
/usr/local/sfcgal/lib64/
/usr/local/gdal/lib/
激活其它postgis的插件:
postgres=# create extension postg
postgis_sfcgal postgis_tiger_geocoder postgis_topology postgres_fdw
postgres=# create extension postgis_tiger_geocoder cascade ;
NOTICE: installing required extension "fuzzystrmatch"
CREATE EXTENSION
postgres=# create extension postgis_topology ;
CREATE EXTENSION
postgres=# create extension postgis_sfcgal ;
CREATE EXTENSION
postgres=# \dxList of installed extensionsName | Version | Schema | Description
------------------------+---------+------------+------------------------------------------------------------fuzzystrmatch | 1.1 | public | determine similarities and distance between stringsplpgsql | 1.0 | pg_catalog | PL/pgSQL procedural languagepostgis | 3.4.3 | public | PostGIS geometry and geography spatial types and functionspostgis_raster | 3.4.3 | public | PostGIS raster types and functionspostgis_sfcgal | 3.4.3 | public | PostGIS SFCGAL functionspostgis_tiger_geocoder | 3.4.3 | tiger | PostGIS tiger geocoder and reverse geocoderpostgis_topology | 3.4.3 | topology | PostGIS topology spatial types and functions
🆗,postgis全系列插件圆满安装完成!!!!!!!!!!!!!!!
15、稍作总结
yum需要安装以下依赖:
yum install automake autoconf gtk2 gtk2-devel libxml2 libxml2-devel xz xz-devel libtool gcc gcc-c++ make gettext sqlite sqlite-devel libffi-devel openjpeg openjpeg-devel gmp-devel mpfr-devel boost* json-c*
gcc版本需要7以上包括7,主要是geos编译需要高版本gcc,本次实验全程使用的gcc高版本7,boost版本要求是48以上
其次,需要python3.6和python3.6的类库也就是lib这些,由于本次实验postgresql数据库是使用yum安装的,因此,python3.6在本文没有体现太多
最后就是yum源的配置,至少需要base源,epel源,update源以及pgdg源,也就是说编译环境非常难配置,需要的依赖是非常多的
总之,postgis插件的安装是比较复杂的,复杂的原因是很多插件需要特定版本,并且依赖之间也是有依赖的,编译此插件需要极大的耐心!!!!!