linux下编译GDAL外加扩展格式支持(二)

上一篇

4、编译libkml库,安装libkml [libkml-1.2.0.tar.gz]

下载地址:http://code.google.com/p/libkml/

此处需要注意:GDAL1.8.1以上版本要求libkml版本最低为1.3.0,因此,我们只能libkml源码进行编译。SVN签出源码:

mkdir /home/jeff/Downloads/libkml-svn
cd /home/jeff/Downloads/libkml-svn
svn checkout http://libkml.googlecode.com/svn/trunk/ libkml-1.3.0
#进入源码目录,更新aclocal.m4
aclocal
#自动生成configure脚本:
./autogen.sh
./configure --prefix=/usr/local/libkml130 --with-expat-include-dir=/usr/local/expat201/include --with-expat-lib-dir=/usr/local/expat201/lib
#如果遇到无法找到curl库或者curl-config的问题,将curl的bin目录添加到PATH环境变量中,再次执行上面的configure命令,再执行下面命令即可:
echo $PATH
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/sbin:/home/jeff/bin:/usr/local/curl7240/bin"
make check
make install

几点注意事项和问题的解决方法:

(1)出现:error: ISO C++ 1998 does not support ‘long long’ [-Werror=long-long]
        问题原因:GCC默认不支持long long类型。
        解决方法:去掉编译选项中的-pedantic项或者在其后添加-Wno-long-long编译选项。(推荐后一种方法)
        该问题在自动编译libkml所依赖的第三方程序包时出现,需要修改的编译选项出现在以下文件夹下的Makefile文件中。

“../libkml-1.3.0/src/kml/base”、
“../libkml-1.3.0/src/kml/convenience”、
“../libkml-1.3.0/src/kml/dom”、
“../libkml-1.3.0/src/kml/engine”、
”../libkml-1.3.0/src/kml/regionator“、
”../libkml-1.3.0/src/kml/xsd“、
”../libkml-1.3.0/examples/engine/“、
”../libkml-1.3.0/examples/gpx/“、
”../libkml-1.3.0/examples/gx/“、
”../libkml-1.3.0/examples/hellonet“
"../libkml-1.3.0/examples/helloworld"
"../libkml-1.3.0/examples/regionator"
"../libkml-1.3.0/examples/xsd"

(2)在编译”../libkml-1.3.0/examples/hellonet“时出现问题:curlfetch.cc:28:23: fatal error: curl/curl.h: No such file or directory

    解决办法:打开该目录下的Makefile文件,找到CPPFLAGS在其后添加curl的头文件路径,如下:

CPPFLAGS = -I/usr/local/expat201/include -I/usr/local/curl7240/include

       或者:

(3)在编译”../libkml-1.3.0/example/hellonet“时出现问题:/usr/bin/ld can not find -lcurl

        解决办法:打开该目录下的Makefile文件,找到LDFLAGS在其后添加curl的lib路径,如下:

LDFLAGS = -L/usr/local/expat201/lib -L/usr/local/curl7240/lib

(4)会遇到类似:

error: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Werror=conversion-null]

    的错误,这是因为:cc1plus: all warnings being treated as errors

    解决办法:只需要找到相应的Makefile,去掉编译选项中的-Werror即可。

(5)若提示找不到:
     a. zlib.h,打开./third_party/Makefile,找到“CPPFLAGS=。。。”,在其后添加-I/usr/programs/zlib126/include
     b. -lz,打开./third_party/Makefile,找到LDFLAGS=。。。,在其后添加-L/usr/programs/zlib126/lib

(6)无问题会看到一大堆类似

Running main() from gtest_main.cc
[==========] Running 4 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 4 tests from KmzCheckLinksTest
[ RUN ] KmzCheckLinksTest.TestNoLinks
[ OK ] KmzCheckLinksTest.TestNoLinks
[ RUN ] KmzCheckLinksTest.TestOverlay
[ OK ] KmzCheckLinksTest.TestOverlay
[ RUN ] KmzCheckLinksTest.TestBadOverlay
[ OK ] KmzCheckLinksTest.TestBadOverlay
[ RUN ] KmzCheckLinksTest.TestNull
[ OK ] KmzCheckLinksTest.TestNull
[----------] Global test environment tear-down
[==========] 4 tests from 1 test case ran.
[ PASSED ] 4 tests.
PASS: kmz_check_links_test
===================
All 14 tests passed
===================

的信息,表示相应功能测试成功,可以安装。

 

附录:自己另一次源码安装libkml-1.3.0的过程:

(1)签出源码

svn checkout http://libkml.googlecode.com/svn/trunk/ libkml-1.3.0

(2)进入libkml-1.3.0目录,参考

http://abloz.com/2010/11/11/autoconf-and-automake.html

进行自己编译安装。

autoscan
ls
#若没有configure.ac,则运行
cp configure.scan configure.ac
#生成aclocal.m4
aclocal
ls
autoconf
#此时若有MACRO错误,类似:configure.ac:8: error: possibly undefined macro: AM_INIT_AUTOMAKE If this token and others are legitimate, please use 
#这是因为修改了configure.ac后,必须aclocal重新生成aclocal.m4,宏才能有定义。
aclocal
ls
autoconf
#调用autoheader生成config.h.in
autoheader
ls
autoconf
./configure --prefix=/usr/local/libkml130 --with-expat-include-dir=/usr/local/expat201/include --with-expat-lib-dir=/usr/local/expat201/lib
automake
#所有错误,执行:
autoreconf --force --install
automake
make
make check #(直到所有测试均为PASS)
make install

此时会遇到(1)、(2)、(3)、(4)、(5)的错误,按照上面的方法解决即可,完成安装libkml最新版本。

 

 未完待续。

全部为本人原创码字,请尊重作者辛苦劳动,转载请注明出处!!!

 

原文地址:https://www.cnblogs.com/yeahgis/p/2446325.html