Ubuntu源码编译gdal3.6.2

在华为云申请了一台Ubuntu v18的机器,乱七八糟的不要装。

apt install build-essential pkg-config -y

cmake-3.21.1

apt-get install openssl libssl-dev

过程参考:Yukon for PostgreSQL_格來羙、日出的博客-CSDN博客

zlib-1.2.9(不需要)

如果用系统的后面gdal会提示inflateValidate@ZLIB_1.2.9

看了下原因,apt安装的是1.2.11。说明版本对应有问题。

我也尝试把zlib的pkgconfig/lib/include拷贝出来,不过依旧报错(gdal文件夹删了重新编)。

zlib Home Site

wget https://codeload.github.com/madler/zlib/zip/refs/tags/v1.2.9
#下载后文件名称不对,对的话可以不改
mv v1.2.9 v1.2.9.zip
unzip v1.2.9.zip
cd zlib-1.2.9
./configure --prefix=/usr/local/zlib-1.2.9
make && make install

#先备份,然后把这里都删了,因为不删后面还是用1.2.11的包,然而apt卸载不掉
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /opt
rm -rf /lib/aarch64-linux-gnu/libz*
ln -s -f /usr/local/zlib-1.2.9/lib/libz.so.1.2.9 /lib/aarch64-linux-gnu/libz.so.1

libtiff

Index of /libtiff/ (osgeo.org)

undefined reference to `TIFFReadDirectory@LIBTIFF_4.0‘ 

 要自己编译,不然gdal会报TIFFReadDirectory@LIBTIFF_4.0

apt remove libtiff5
#可以先尝试编译下,使用build是迫不得已,提示选择平台
wget http://download.osgeo.org/libtiff/tiff-4.0.9.zip
./configure --prefix=/usr/local/tiff-4.0.9 \
--build=aarch64-unknown-linux-gnu
make && make install

 #虽然版本不对应,zlib1g-dev对应的是1.2.11,但是用到了一些头文件 
apt install zlib1g-dev

#可以先尝试编译下,使用build是迫不得已,提示选择平台
./configure --prefix=/usr/local/tiff-4.0.9 \
--with-zlib-include-dir=/usr/local/zlib-1.2.9/include \
--with-zlib-lib-dir=/usr/local/zlib-1.2.9/lib/libz.so.1.2.9 \
--build=aarch64-unknown-linux-gnu

环境变量 

/etc/profile
#tiff
export TIFF_HOME=/usr/local/tiff-4.0.9
export TIFF_CFLAGS=$TIFF_HOME/include
export TIFF_LIBS=$TIFF_HOME/lib/pkgconfig
export PKG_CONFIG_PATH=$TIFF_LIBS:$PKG_CONFIG_PATH

/etc/ld.so.conf
/usr/local/tiff-4.0.9/lib

curl-7.29.0(不需要)

curl downloads

要自己编译,GDAL编译会报错  curl_mime_init@CURL_GNUTLS_3

事先声明,curl这种编译方法会不全,需要更详细看官网

apt install libcurl4 libcurl4-openssl-dev curl 

wget https://curl.se/download/archeology/curl-7.29.0.tar.gz
./configure --prefix=/usr/local/curl-7.29.0 
#--with-zlib=/usr/local/zlib-1.2.9
make && make install

proj-9.2.1

wget https://codeload.github.com/OSGeo/PROJ/zip/refs/tags/9.2.1
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/proj-9.2.1 \
-DSQLITE3_INCLUDE_DIR=/usr/local/sqlite3400000/include \
-DSQLITE3_LIBRARY=/usr/local/sqlite3400000/lib/libsqlite3.so \
-DTIFF_INCLUDE_DIR=/usr/local/tiff-4.0.9/include \
-DTIFF_LIBRARY=/usr/local/tiff-4.0.9/lib/libtiff.so \
-DBUILD_TESTING=OFF

编译前环境

#cmake
export CMAKE_HOME=/usr/local/cmake-3.21.1
export PATH=$CMAKE_HOME/bin:$PATH
#sqlite
export SQLITE_HOME=/usr/local/sqlite3400000
export PATH=$SQLITE_HOME/bin:$PATH
export PKG_CONFIG_PATH=$SQLITE_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
#tiff
export TIFF_HOME=/usr/local/tiff-4.0.9
export TIFF_CFLAGS=$TIFF_HOME/include
export TIFF_LIBS=$TIFF_HOME/lib/pkgconfig
export PKG_CONFIG_PATH=$TIFF_LIBS:$PKG_CONFIG_PATH
#curl
#export CURL_HOME=/usr/local/curl-7.29.0
#export CURL_CFLAGS=$TIFF_HOME/include
#export CURL_LIBS=$TIFF_HOME/lib/pkgconfig
#export PKG_CONFIG_PATH=$CURL_LIBS:$PKG_CONFIG_PATH
#proj
export PROJ_HOME=/usr/local/proj-9.2.1
export PKG_CONFIG_PATH=$PROJ_HOME/lib/pkgconfig:$PKG_CONFIG_PATH
/usr/local/tiff-4.0.9/lib
/usr/local/sqlite3400000/lib
/usr/local/freexl-2.0.0/lib
/usr/local/proj-9.2.1/lib

gdal-3.6.2

#如果有highgo库,把libz依赖移走,会和gdal的libz冲突
mv /opt/highgo/hgdb-see-4.5.8/lib/libz.so.1 /opt/

cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/gdal-3.6.2  \
-DBUILD_TESTING=OFF \
-DTIFF_INCLUDE_DIR=/usr/local/tiff-4.0.9/include \
-DTIFF_LIBRARY=/usr/local/tiff-4.0.9/lib/libtiff.so \
-DSQLite3_INCLUDE_DIR=/usr/local/sqlite3400000/include \
-DSQLite3_LIBRARY=/usr/local/sqlite3400000/lib/libsqlite3.so \

#支持xls文件格式
-DFREEXL_INCLUDE_DIR=/usr/local/freexl-2.0.0/include \
-DFREEXL_LIBRARY=/usr/local/freexl-2.0.0/lib/libfreexl.so 

#支持pg,可选项
-DOGR_ENABLE_DRIVER_PG=ON \
-DPostgreSQL_INCLUDE_DIR=/opt/highgo/hgdb-see-4.5.8/include \
-DPostgreSQL_LIBRARY=/opt/highgo/hgdb-see-4.5.8/lib/libpq.so 

#如果上面不装zlib,这里不需要
-DZLIB_INCLUDE_DIR=/usr/local/zlib-1.2.9/include 
-DZLIB_LIBRARY=/usr/local/zlib-1.2.9/lib/libz.so.1.2.9

-DPROJ_INCLUDE_DIR=/usr/local/proj-9.2.1/include 
-DPROJ_LIBRARY=/usr/local/proj-9.2.1/lib/libproj.so.25.9.2.1 

Manually-specified variables were not used by the project:

    PROJ_INCLUDE_DIR
    PROJ_LIBRARY

PROJ is detected in priority through CMake config files, in which case PROJ_INCLUDE_DIR and PROJ_LIBRARY_RELEASE will be ignored.

官方回复:通过 CMake 配置文件优先检测 PROJ,在这种情况下 PROJ_INCLUDE_DIR 和 PROJ_LIBRARY_RELEASE 将被忽略。 

配置环境

vi /etc/profile
#gdal
export GDAL_HOME=/usr/local/gdal-3.6.2
export PATH=$GDAL_HOME/bin:$PATH
export PKG_CONFIG_PATH=$GDAL_HOME/lib64/pkgconfig:$PKG_CONFIG_PATH
source /etc/profile
vi /etc/ld.so.conf
...
/usr/local/gdal-3.6.2/lib
/opt/highgo/hgdb-see-4.5.8/lib  #配上libpq

ldconfig -v

 验证 GDAL

#支持格式
ogr2ogr --formats

#导入shp
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='highgo' user='sysdba' password='Test@123' port=5866" /opt/110m_physical/ne_110m_ocean.shp

#导入xls
ogr2ogr -f "PostgreSQL" PG:"host='127.0.0.1' dbname='highgo' user='sysdba' password='Test@123' port=5866" /opt/dltbxz_tqmj.xlsx

你可能感兴趣的:(PostGIS,arm开发,ubuntu,服务器)