Linux18.04安装GDAL2.0.0 gdalserver.c编译失败的问题
1.下载GDAL源代码
下载源码链接:http://download.osgeo.org/gdal/
官方提供的安装方法:https://trac.osgeo.org/gdal/wiki/BuildingOnUnix
我自己的理解是安装GDAL前需要一些前置的库,但是官方文档并没有对此给出详细说明。我安装了proj和geos,分别是proj4.9.2、geos3.5.2。
geos下载链接:https://libgeos.org/usage/download/
proj下载链接:http://download.osgeo.org/proj/
这两个安装方式和GDAL一样。./configure 这一步,后面不用加东西,默认路径就行。
2.make步骤gdalserver.c编译出问题
gdalserver.c: In function 'CreateSocketAndBindAndListen':
gdalserver.c:124:21: error: storage size of 'sHints' isn't known
struct addrinfo sHints;
^~~~~~
gdalserver.c:126:31: error: invalid application of 'sizeof' to incomplete type 'struct addrinfo'
memset(&sHints, 0, sizeof(struct addrinfo));
^~~~~~
gdalserver.c:129:23: error: 'AI_PASSIVE' undeclared (first use in this function); did you mean 'AF_WANPIPE'?
sHints.ai_flags = AI_PASSIVE;
^~~~~~~~~~
AF_WANPIPE
gdalserver.c:129:23: note: each undeclared identifier is reported only once for each function it appears in
gdalserver.c:132:12: warning: implicit declaration of function 'getaddrinfo' [-Wimplicit-function-declaration]
nRet = getaddrinfo(NULL, pszService, &sHints, &psResults);
^~~~~~~~~~~
gdalserver.c:135:48: warning: implicit declaration of function 'gai_strerror'; did you mean 'strerror'? [-Wimplicit-function-declaration]
fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(nRet));
^~~~~~~~~~~~
strerror
gdalserver.c:135:42: warning: format '%s' expects argument of type 'char ', but argument 3 has type 'int' [-Wformat=]
fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(nRet));
~^ ~~~~~~~~~~~~~~~~~~
%d
gdalserver.c:141:39: error: dereferencing pointer to incomplete type 'struct addrinfo'
psResultsIter = psResultsIter->ai_next)
^~
gdalserver.c:162:5: warning: implicit declaration of function 'freeaddrinfo' [-Wimplicit-function-declaration]
freeaddrinfo(psResults);
^~~~~~~~~~~~
gdalserver.c:124:21: warning: unused variable 'sHints' [-Wunused-variable]
struct addrinfo sHints;
^~~~~~
查阅资料后,在官方文档查到同样的错误,https://trac.osgeo.org/gdal/ticket/6073#no1
修改方法是 gdal-2.0.0/apps/gdalserver.c 中
#define _XOPEN_SOURCE 修改成
#define _XOPEN_SOURCE 600
修改之后再正常安装就可以了。