C++学习(三四六)cygwin 交叉编译Android gdal

官方说gdal的android版本是仍在做的一项工作:BuildingForAndroid – GDALhttps://trac.osgeo.org/gdal/wiki/BuildingForAndroid

cygwin android-ndk-r19c gdal2.3.2 win10

1、建立环境变量

交叉编译工具链所在的bin目录放入windows下的Path环境变量,cygwin能自动获取到该环境变量,从而能找到交叉编译工具链。

D:\android-ndk-r19c\toolchains\llvm\prebuilt\windows-x86_64\bin

2、建立脚本文件android_build.sh,内容为:

#!/bin/sh
#cd E:/osg-osgearth-source/other_3rdParty/gdal-2.3.2

export PATH=/usr/local/bin:/usr/bin:/cygdrive/d/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin
export HOST_TAG=windows-x86_64

export  TOOLCHAIN_HOME=D:/android-ndk-r19c/toolchains/llvm/prebuilt/$HOST_TAG

export AR=$TOOLCHAIN_HOME/bin/aarch64-linux-android-ar.exe
export AS=$TOOLCHAIN_HOME/bin/aarch64-linux-android-as.exe
export RANLIB=$TOOLCHAIN_HOME/bin/aarch64-linux-android-ranlib.exe
export CC=$TOOLCHAIN_HOME/bin/aarch64-linux-android28-clang
export CXX=$TOOLCHAIN_HOME/bin/aarch64-linux-android28-clang++
export LD=$TOOLCHAIN_HOME/bin/aarch64-linux-android-ld.exe
export STRIP=$TOOLCHAIN_HOME/bin/aarch64-linux-android-strip.exe

export NM=$TOOLCHAIN_HOME/bin/aarch64-linux-android-nm.exe

export   PATH=$TOOLCHAIN_HOME/bin:$PATH

./configure --host=aarch64-linux-android --prefix=E:/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a --with-gif --with-ogr --with-geos --with-libz=internal

还有地方讲如此配置(未使用)

Android NDK20编译 GDAL 2.4.3 - 知乎)./configure --prefix=/home/zouleid/gdal/android --with-threads --with-ogr --host=arm-linux-androideabi  --without-geos --with-libz=internal --with-png=internal --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-sqlite3=yes -without-libtool -with-oci=no --with-xerces=no --with-expat=no --with-libkml=no --without-jpeg12 --without-bsb --without-grib --without-openfilegdb --without--filegdb --without-pam  --without-pdf --without-sentinel2 --without-ctg --without-kmlsuperoverlay --without-wcs --without-vdv --without-dgn --without-dwg

编译Android版本的GDAL库_zzzzllll2006的博客-CSDN博客)./configure --prefix=/home/zouleid/gdal/android --with-threads --with-ogr --host=arm-linux-androideabi  --without-geos --with-libz=internal --with-png=internal --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-sqlite3=yes -without-libtool -with-oci=no --with-xerces=no --with-expat=no --with-libkml=no --without-jpeg12 --without-bsb --without-grib --without-openfilegdb --without--filegdb --without-pam  --without-pdf --without-sentinel2 --without-ctg --without-kmlsuperoverlay --without-wcs --without-vdv --without-dgn --without-dwg

执行后,一定要在终端打印的内容中搜索看到  checking whether we are cross compiling... yes,这一行才算成功。

注意在cygwin中,android_build.sh行结尾为换行/n,不是windows下的回车换行/r/n,使用notepad很容易替换处理。

修改根目录下的GDALmake.opt,在CXXFLAGS中增加-fPIC,在CFLAGS中增加-fPIC

3、执行脚本

启动cygwin,切换到gdal所在目录,执行

./gdal_android_build.sh

4、修改根目录下的GDALmake.opt,将GDAL_ROOT    =    /cygdrive/e/osg-osgearth-source/other_3rdParty/gdal-2.3.2改为GDAL_ROOT    =   e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2

将prefix   =    /cygdrive/E/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a改为E:/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a

修改根目录下的libtool,将RANLIB="/bin/aarch64-linux-android-ranlib.exe"改为RANLIB="D:/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android-ranlib.exe"

修改根目录下的GDALmake.opt,在CFLAGS、CXXFLAGS后添加-fno-use-cxa-atexit

修改根目录下的GNUmakefile,将

$(LIBGDAL):    $(GDAL_OBJ:.o=.lo)
    $(LD) $(LDFLAGS) $(LIBS) -o $@ $(sort $(wildcard $(GDAL_OBJ:.o=.lo))) \
        -rpath $(INST_LIB) \
        -no-undefined \
        -version-info $(LIBGDAL_CURRENT):$(LIBGDAL_REVISION):$(LIBGDAL_AGE)

改为

$(LIBGDAL):    $(GDAL_OBJ:.o=.lo)
    $(LD) $(LDFLAGS) $(LIBS) -o $@ $(sort $(wildcard $(GDAL_OBJ:.o=.lo))) \
        -no-undefined \
        -version-info $(LIBGDAL_CURRENT):$(LIBGDAL_REVISION):$(LIBGDAL_AGE)

rpath会造成链接问题(C++学习(三九四)relocation R_AARCH64_ADR_PREL_PG_HI21 undefined reference to `__dso_handle‘_hankern的专栏-CSDN博客

没有-rpath就无法生成动态链接库!!!!!!!!!!!!!

修改apps/GNUmakefile,注释掉所有BIN_LIST,一些应用生成有问题,但是gdal一般也用不到。

修改libtool文件,去掉-nostdlib选项

archive_cmds="\$CC \$pic_flag -shared \$predep_objects \$libobjs \$deplibs \$postdep_objects \$compiler_flags \$wl-soname \$wl\$soname -o \$lib"
archive_expsym_cmds="\$CC \$pic_flag -shared \$predep_objects \$libobjs \$deplibs \$postdep_objects \$compiler_flags \$wl-soname \$wl\$soname \$wl-retain-symbols-file \$wl\$export_symbols -o \$lib"
#archive_cmds="\$CC \$pic_flag -shared -nostdlib \$predep_objects \$libobjs \$deplibs \$postdep_objects \$compiler_flags \$wl-soname \$wl\$soname -o \$lib"
#archive_expsym_cmds="\$CC \$pic_flag -shared -nostdlib \$predep_objects \$libobjs \$deplibs \$postdep_objects \$compiler_flags \$wl-soname \$wl\$soname \$wl-retain-symbols-file \$wl\$export_symbols -o \$lib"

5、执行make

6、执行make install

注意事项(BuildingOnUnix – GDAL):

1、The shared library building is pretty specific to the GNU tool chain. If you are using something different than GNU C++, then you will likely finding that the .so files isn't built successfully. You could just link against the static libraries (normally gdal/gdal.a) or you could hack LD_SHARED command in gdal/GDALmake.opt to work on your platform. For the SGI a value of c++ -shared -all is often suitable.

共享库构建非常特定于GNU工具链。如果使用不同于GNU C++的不同的东西,那么您可能会发现.so文件没有成功构建。您可以只链接静态库(通常是gdal/gdal.a),也可以在gdal/GDALmake.opt中使用LD_SHARED命令在您的平台上工作。对于SGI,C++ -shared -all的值通常是合适的。

2、If you find build problems with one of the format drivers that you don't care about, just remove the format from the GDAL_FORMATS line at the bottom of gdal/GDALmake.opt, do a make clean, and make. This will drop it from the build and default runtime registration.

如果您发现其中一个格式驱动程序存在生成问题,而您并不关心这些问题,只需从GDAL/GDALmake.opt底部的GDAL_FORMATS行中删除该格式,然后执行“make clean”和“make”。这将从生成和默认运行时注册中删除它。

export HOST_TAG=windows-x86_64

export  TOOLCHAIN_HOME=D:/android-ndk-r19c/toolchains/llvm/prebuilt/$HOST_TAG

export AR=$TOOLCHAIN_HOME/bin/aarch64-linux-android-ar.exe
export AS=$TOOLCHAIN_HOME/bin/aarch64-linux-android-as.exe
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib.exe
export CC=$TOOLCHAIN_HOME/bin/aarch64-linux-android28-clang
export CXX=$TOOLCHAIN_HOME/bin/aarch64-linux-android28-clang++
export LD=$TOOLCHAIN_HOME/bin/aarch64-linux-android-ld.exe
export STRIP=$TOOLCHAIN_HOME/bin/aarch64-linux-android-strip.exe

export   LIBS="-lstdc++ -liconv -lgnustl_shared"

export   PATH=$TOOLCHAIN_HOME/bin:$PATH

export   LIBS="-lstdc++ -liconv -lgnustl_shared"

TOOLCHAIN_HOME 后接生成的工具链路径。


 

执行source /etc/profile命令让设置生效。

切换到gdal所在目录

./configure --host=aarch64-linux-android --prefix=/cygdrive/E/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a --without-gif --with-ogr --with-geos --with-libz=internal

执行后,一定要在终端打印的内容中搜索看到  checking whether we are cross compiling... yes,这一行才算成功。

LIBS="-lsupc++ -lstdc++ -liconv -lgnustl_shared" ./configure --host=aarch64-linux-android --prefix=/home/ubuntu/software/gdal-2.3.1--without-gif --with-ogr --with-geos --with-libz=internal


 

LIBS="-lsupc++ -lstdc++" ./configure --host=aarch64-linux-android --prefix=/cygdrive/E/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a --without-gif --with-ogr --with-geos --with-libz=internal

1、下载cygwin,在windows下编译gdal需要在此环境下进行。


 

2、需要使用有gcc的交叉编译工具链,可从aarch64-linux-android-4.9下载,。

3、交叉编译工具链所在的bin目录放入windows下的Path环境变量,cygwin能自动获取到该环境变量,从而能找到交叉编译工具链。

D:\aarch64-linux-android-4.9-marshmallow\bin

make-standalone-toolchain.sh --arch=arm64  --platform=android-28  --install-dir=d:\aarch64-linux-android-hankern  --force

make-standalone-toolchain.sh --arch=arm64  --toolchain=aarch64-linux-android-4.9  --platform=android-28  --install-dir=d:\aarch64-linux-android-hankern  --force

使用r16b的交叉编译工具链,这里面有gcc

D:\android-ndk-r16b\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin

4、执行configure

在cygwin中,切换到gdal所在的目录,执行:

./configure --prefix=/cygdrive/E/Projects/QT5.12/osg_earth_android_build/3rdpartyAndroid/gdal/obj/local/armeabi-v8a --host=aarch64-linux-android  --with-threads --with-ogr --without-geos --with-libz=internal --with-png=internal --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-sqlite3=yes -without-libtool -with-oci=no --with-xerces=no --with-expat=no --with-libkml=no --without-jpeg12 --without-bsb --without-grib --without-openfilegdb --without--filegdb --without-pam  --without-pdf --without-sentinel2 --without-ctg --without-kmlsuperoverlay --without-wcs --without-vdv --without-dgn --without-dwg

问题1:no acceptable C compiler found in $PATH

解决方法1:交叉编译工具链不正确,按步骤1下载。

gdal是通过下面的语句进行链接的

e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/libtool --mode=link --silent D:/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android28-clang++    -lm -ldl                    -o libgdal.la ./ogr/gml2ogrgeometry.lo ./ogr/ogr2gmlgeometry.lo ./ogr/ogr_api.lo ./ogr/ogr_expat.lo ./ogr/ogr_fromepsg.lo ./ogr/ogr_geo_utils.lo ./ogr/ogr_geocoding.lo ./ogr/ogr_opt.lo ./ogr/ogr_srs_dict.lo ./ogr/ogr_srs_erm.lo ./ogr/ogr_srs_esri.lo ./ogr/ogr_srs_ozi.lo ./ogr/ogr_srs_panorama.lo ./ogr/ogr_srs_pci.lo ./ogr/ogr_srs_proj4.lo ./ogr/ogr_srs_usgs.lo ./ogr/ogr_srs_validate.lo ./ogr/ogr_srs_xml.lo ./ogr/ogr_srsnode.lo ./ogr/ogr_xerces.lo ./ogr/ograpispy.lo ./ogr/ograssemblepolygon.lo ./ogr/ogrcircularstring.lo ./ogr/ogrcompoundcurve.lo ./ogr/ogrct.lo ./ogr/ogrcurve.lo ./ogr/ogrcurvecollection.lo ./ogr/ogrcurvepolygon.lo ./ogr/ogrfeature.lo ./ogr/ogrfeaturedefn.lo ./ogr/ogrfeaturequery.lo ./ogr/ogrfeaturestyle.lo ./ogr/ogrfielddefn.lo ./ogr/ogrgeomediageometry.lo ./ogr/ogrgeometry.lo ./ogr/ogrgeometrycollection.lo ./ogr/ogrgeometryfactory.lo ./ogr/ogrgeomfielddefn.lo ./ogr/ogrlinearring.lo ./ogr/ogrlinestring.lo ./ogr/ogrmulticurve.lo ./ogr/ogrmultilinestring.lo ./ogr/ogrmultipoint.lo ./ogr/ogrmultipolygon.lo ./ogr/ogrmultisurface.lo ./ogr/ogrpgeogeometry.lo ./ogr/ogrpoint.lo ./ogr/ogrpolygon.lo ./ogr/ogrpolyhedralsurface.lo ./ogr/ogrspatialreference.lo ./ogr/ogrsurface.lo ./ogr/ogrtriangle.lo ./ogr/ogrtriangulatedsurface.lo ./ogr/ogrutils.lo ./ogr/osr_cs_wkt.lo ./ogr/osr_cs_wkt_parser.lo ./ogr/swq.lo ./ogr/swq_expr_node.lo ./ogr/swq_op_general.lo ./ogr/swq_op_registrar.lo ./ogr/swq_parser.lo ./ogr/swq_select.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/contour.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/delaunay.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdal_crs.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdal_octave.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdal_rpc.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdal_simplesurf.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdal_tps.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalapplyverticalshiftgrid.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalchecksum.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalcutline.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdaldither.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalgeoloc.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalgrid.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalgridavx.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalgridsse.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdallinearsystem.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalmatching.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalmediancut.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalpansharpen.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalproximity.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalrasterize.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalrasterpolygonenumerator.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalsievefilter.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalsimplewarp.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdaltransformer.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdaltransformgeolocs.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalwarper.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalwarpkernel.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalwarpkernel_opencl.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/gdalwarpoperation.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/llrasterize.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/polygonize.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/rasterfill.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg/thinplatespline.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/commonutils.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdal_grid_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdal_rasterize_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdal_translate_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdalbuildvrt_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdaldem_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdalinfo_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/gdalwarp_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/nearblack_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps/ogr2ogr_lib.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/BitMask.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/BitMask2.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/BitStuffer.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/BitStuffer2.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/CntZImage.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/EnvisatFile.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/Huffman.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/IdrisiDataset.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/IngrTypes.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/IntergraphBand.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/IntergraphDataset.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/JPEG12_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/JPEG_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/JPNG_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/JpegHelper.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/LERC_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/Lerc2.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/PNG_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/Packer_RLE.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/RLE.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/Raw_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/Tif_band.lo e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/o/_getcell.lo e:/osg-osgearth-so

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值