0%

Windows的cygwin环境下编译GMT

问答

问:在windows下通常都是直接安装GMT的exe程序,这样导致不能使用github上最新的开发版,而开发版通常fix了很多的bug。如果想在win上安装编译开发版本,怎么办?
答:应该尝试cygwin+cmake。

问:cygwin是什么?怎么使用?
答:可以看这里. cygwin的各个库升级都是通过setup**.exe实现的,每一次升级或者安装新的模块,都要打开这个程序。用习惯了,不觉得麻烦。

问:cmake怎么在这下面安装?
答:可以使用setup**.exe,选择cmake进行安装。

安装完成后打开命令行界面,查看cygwin版本:

1
2
3
4
5
yangleir@DESKTOP-FVRFATD ~
$ cmake --version
cmake version 3.14.5

CMake suite maintained and supported by Kitware (kitware.com/cmake).

问:GMT的诸多依赖程序怎么办?
答:GMT的building指南已经给出了依赖库,如下:

cmake, fftw, fftw-devel, gcc, g++, ghostscript, gv, libcurl-devel, libnetcdf7, libnetcdf7-devel, libnpcr0, libnpcr0-devel, make, openssh, subversion, xinit, zlib, zlib-devel, liblapack-devel

其中cmake已经安装了,其他程序安装类似。再次打开setup**.exe,选择上述程序。可以一次全部选择安装,可能需要花点时间下载和编译。

问:GMT的编译步骤呢?
答:余下的和Linux编译源程序一样。分别下载源文件,设置cmake参数,进行cmake编译。
下面的结果是只修改了GMT安装目录得到的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
*
* GMT Version: : 6.1.0
*
* Options:
* Found GSHHG database : GSHHG_PATH-NOTFOUND ()
* Found DCW-GMT database : DCW_PATH-NOTFOUND
* Found GMT data server : https://oceania.generic-mapping-tools.org
* NetCDF library : /usr/lib/libnetcdf.dll.a
* NetCDF include dir : /usr/include
* Curl library :
* Curl include dir : /usr/include
* GDAL library : GDAL_LIBRARY-NOTFOUND
* GDAL include dir : /cygdrive/c/OSGeo4W64/include
* FFTW library : /usr/lib/libfftw3f.dll.a
* FFTW threads library : /usr/lib/libfftw3f_threads.dll.a
* FFTW include dir : /usr/include
* Accelerate Framework :
* Regex support : PCRE (/usr/lib/libpcre.dll.a)
* ZLIB library :
* ZLIB include dir : /usr/include
* LAPACK library : yes
* BLAS library : yes
* License restriction : no
* Triangulation method : Shewchuk
* OpenMP support : disabled (GMT_OPENMP not set)
* GLIB GTHREAD support :
* Build generator : Unix Makefiles
* Build mode : shared
* Build GMT core : always [libgmt-6.dll]
* Build PSL library : always [libpostscriptlight-6.dll]
* Build GMT supplements : yes [supplements.so]
* Build GMT for developers : yes
* Build proto supplements : none
* Build module links : no
* Found Ghostscript (gs) : yes (9.27)
* Found GraphicsMagick (gm) : yes (1.3.34)
* Found ffmpeg : yes (7.2.0)
* Found open : no
* Found ogr2ogr : yes (2.4.1)
* Found gdal_translate : yes (2.4.1)
*
* Locations:
* Installing GMT in : /home/yangleir/local
* GMT_DATADIR : /home/yangleir/local/share
* GMT_DOCDIR : /home/yangleir/local/share/doc
* GMT_MANDIR : /home/yangleir/local/share/man
-- Configuring done
-- Generating done
-- Build files have been written to: /cygdrive/c/Users/yangleir/Documents/GMT/gmt-master/build

问题

存在的问题:我指定gshhg路径如下,但是无法找到,尝试/cygdrive/c/路径也一样找不到。DCW也是一样的结果。因此在进行cmake时,选择了忽略。

1
set (GSHHG_ROOT C:/Users/yangleir/Documents/GMT/gshhg-gmt-2.3.7/)

至此安装完毕,除了缺少自动安装的海岸线文件。在安装目录下生成了如下文件,和win不同的时,gmt.exe包含了全部的模块,因此使用时必须前缀gmt。

1
2
3
4
yangleir@DESKTOP-FVRFATD ~/local/bin
$ ls
gmt.exe gmt-config isogmt libpostscriptlight-6.dll
gmt_shell_functions.sh gmtswitch libgmt-6.dll

测试

添加路径:编辑

1
2
yangleir@DESKTOP-FVRFATD ~
$ vi .bash_profile

添加:

1
export PATH=/home/yangleir/local/bin/:$PATH

执行:

1
2
yangleir@DESKTOP-FVRFATD ~
$ source .bash_profile

测试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
yangleir@DESKTOP-FVRFATD ~
$ gmt

GMT - The Generic Mapping Tools, Version 6.1.0 [64-bit] [12 cores]
(c) 1991-2019 The GMT Team (https://www.generic-mapping-tools.org/team.html).

Supported in part by the US National Science Foundation (http://www.nsf.gov/)
and volunteers from around the world.

GMT is distributed under the GNU LGPL License (http://www.gnu.org/licenses/lgpl.html).

usage: gmt [options]
gmt <module name> [<module-options>]

options:
--help List descriptions of available GMT modules.
--new-script[=L] Write GMT modern mode script template to stdout.
Optionally specify bash|csh|batch [Default is current shell]
--show-bindir Show directory with GMT executables.
--show-citation Show the most recent citation for GMT.
--show-classic Show all classic module names.
--show-cores Show number of available cores.
--show-datadir Show directory/ies with user data.
--show-dataserver Show URL of the remote GMT data server.
--show-doi Show the DOI for the current release.
--show-modules Show all modern module names.
--show-library Show path of the shared GMT library.
--show-plugindir Show directory for plug-ins.
--show-sharedir Show directory for shared GMT resources.
--version Print GMT version number.

if <module-options> is '=' we call exit (0) if module exist and non-zero otherwise.

说明已经安装上了GMT的开发版6.1.0.

这种方法对win系统中通过exe安装的GMT路径不干涉,在MINGW64中输入gmt,依然是稳定版6.0.0。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
yangleir@DESKTOP-FVRFATD MINGW64 ~
$ gmt

GMT - The Generic Mapping Tools, Version 6.0.0 [64-bit] [MP] [12 cores]
(c) 1991-2019 The GMT Team (https://www.generic-mapping-tools.org/team.html).

Supported in part by the US National Science Foundation (http://www.nsf.gov/)
and volunteers from around the world.

GMT is distributed under the GNU LGP License (http://www.gnu.org/licenses/lgpl.html).

usage: gmt [options]
gmt <module name> [<module-options>]

options:
--help List descriptions of available GMT modules.
--new-script[=L] Write GMT modern mode script template to stdout.
Optionally specify bash|csh|batch [Default is current shell]
--show-bindir Show directory with GMT executables.
--show-citation Show the most recent citation for GMT.
--show-cores Show number of available cores.
--show-datadir Show directory/ies with user data.
--show-dataserver Show URL of the remote GMT data server.
--show-doi Show the DOI for the current release.
--show-modules Show all module names.
--show-library Show path of the shared GMT library.
--show-plugindir Show directory for plug-ins.
--show-sharedir Show directory for shared GMT resources.
--version Print GMT version number.

if <module-options> is '=' we call exit (0) if module exist and non-zero otherwise.

需要注意:cygwin方法编译的GMT不能在别的环境中使用,如MINGW64和win自带的cmd,因为需要加载cygwin的一些模块,别的环境是不通的。

使用

gmt 6.1.0 修复一个博客中提到的bug,看看能不能顺利运行?
结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
yangleir@DESKTOP-FVRFATD /cygdrive/c/Users/yangleir/Documents/jianguoyun/Documents/GMT/gmt_exs/exs/great_circle
$ ./a.sh
Warning! ***HDF5 library version mismatched error***
The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.5, library is 1.10.6
SUMMARY OF THE HDF5 CONFIGURATION
=================================

General Information:
-------------------
HDF5 Version: 1.10.6
Configured on: Sat Jan 18 22:29:58 CET 2020
Configured by: Marco@LAPTOP-82F08ILC
Host system: x86_64-pc-cygwin
Uname information: CYGWIN_NT-10.0 LAPTOP-82F08ILC 3.1.2(0.340/5/3) 2020-01-12 11:00 x86_64 Cygwin
Byte sex: little-endian
Installation point: /usr

Compiling Options:
------------------
Build Mode: production
Debugging Symbols: no
Asserts: no
Profiling: no
Optimization Level: high

Linking Options:
----------------
Libraries: shared
Statically Linked Executables:
LDFLAGS:
H5_LDFLAGS: -no-undefined
AM_LDFLAGS:
Extra libraries: -lz -ldl -lm
Archiver: ar
AR_FLAGS: cr
Ranlib: ranlib

Languages:
----------
C: yes
C Compiler: /usr/bin/gcc ( gcc (GCC) 7.4.0)
CPPFLAGS:
H5_CPPFLAGS: -DNDEBUG -UH5_DEBUG_API
AM_CPPFLAGS:
C Flags: -ggdb -O2 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/cygdrive/d/cyg_pub/devel/hdf5/hdf5-1.10.6-1.x86_64/build=/usr/src/debug/hdf5-1.10.6-1 -fdebug-prefix-map=/cygdrive/d/cyg_pub/devel/hdf5/hdf5-1.10.6-1.x86_64/src/hdf5-1.10.6=/usr/src/debug/hdf5-1.10.6-1
H5 C Flags: -pedantic -Wall -Wextra -Wbad-function-cast -Wc++-compat -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdisabled-optimization -Wfloat-equal -Wformat=2 -Wno-format-nonliteral -Winit-self -Winvalid-pch -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-enum -Wswitch-default -Wundef -Wunused-macros -Wunsafe-loop-optimizations -Wwrite-strings -Wlogical-op -Wlarger-than=2560 -Wsync-nand -Wframe-larger-than=16384 -Wpacked-bitfield-compat -Wstrict-overflow=5 -Wjump-misses-init -Wunsuffixed-float-constants -Wdouble-promotion -Wtrampolines -Wstack-usage=8192 -Wvector-operation-performance -Wdate-time -Warray-bounds=2 -Wc99-c11-compat -Wnull-dereference -Wunused-const-variable -Wduplicated-cond -Whsa -Wnormalized -Walloc-zero -Walloca -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wrestrict -fstdarg-opt -s -Wno-inline -Wno-aggregate-return -Wno-missing-format-attribute -Wno-missing-noreturn -Wno-suggest-attribute=const -Wno-suggest-attribute=pure -Wno-suggest-attribute=noreturn -Wno-suggest-attribute=format -O3
AM C Flags:
Shared C Library: yes
Static C Library: no


Fortran: no

C++: yes
C++ Compiler: /usr/bin/g++ ( g++ (GCC) 7.4.0)
C++ Flags: -ggdb -O2 -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/cygdrive/d/cyg_pub/devel/hdf5/hdf5-1.10.6-1.x86_64/build=/usr/src/debug/hdf5-1.10.6-1 -fdebug-prefix-map=/cygdrive/d/cyg_pub/devel/hdf5/hdf5-1.10.6-1.x86_64/src/hdf5-1.10.6=/usr/src/debug/hdf5-1.10.6-1
H5 C++ Flags: -pedantic -Wall -W -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wredundant-decls -Winline -Wsign-promo -Woverloaded-virtual -Wold-style-cast -Weffc++ -Wreorder -Wnon-virtual-dtor -Wctor-dtor-privacy -Wabi -finline-functions -s -O
AM C++ Flags:
Shared C++ Library: yes
Static C++ Library: no

Java: no


Features:
---------
Parallel HDF5: no
Parallel Filtered Dataset Writes: no
Large Parallel I/O: no
High-level library: yes
Build HDF5 Tests: yes
Build HDF5 Tools: yes
Threadsafety: no
Default API mapping: v110
With deprecated public symbols: yes
I/O filters (external): deflate(zlib)
MPE: no
Direct VFD: no
(Read-Only) S3 VFD: no
(Read-Only) HDFS VFD: no
dmalloc: no
Packages w/ extra debug output: none
API tracing: no
Using memory checker: no
Memory allocation sanity checks: no
Function stack tracing: no
Strict file format checks: no
Optimization instrumentation: no

上面都是HDF5相关的信息,这是根据官网的安装说明设置HDF5_DISABLE_VERSION_CHECK=2的结果?

关于岸线文件找不到的问题,提示如下,版本不识别?

1
2
CMake Error at cmake/modules/FindGSHHG.cmake:69 (message):
Cannot determine GSHHG version:

总结

虽然可以编译,但是还需要改进:
-找到海岸线
-匹配唯一的HDF5等库。
-cygwin的gs库有bug,更换。

不建议使用这种方法进行GMT的开发版安装。