Compilation of GMT6 from src on Mac OS

Hi all,

I’m trying to get GMT6 compiled from source on an old MacPro (late 2012 version) running High Sierra (10.13.6) but keep having a few strange issues with gmt giving a segmentation fault (both my locally compiled/built version as well as the v6 dmg I downloaded from GitHub).

I am building GMT from source, with homebrew for dependencies, apart from the GDAL library where I use William Kyngesbury’s Framework for QGIS/Mac (installed in /Library/Frameworks and on path).

Homebrew & friends is updated brew update && brew upgrade, running cmake .. in a fresh build directory gives:

*
*  GMT Version:               : 6.1.0_41de545_2019.11.23
*
*  Options:
*  Found GSHHG database       : /Users/<user>/geodata/coastlines/gshhg-gmt-2.3.6 (2.3.6)
*  Found DCW-GMT database     : /Users/<user>/geodata/culture/dcw-gmt-1.1.2
*  Found GMT data server      : https://oceania.generic-mapping-tools.org
*  NetCDF library             : /usr/local/Cellar/netcdf/4.6.3_1/lib/libnetcdf.dylib
*  NetCDF include dir         : /usr/local/Cellar/netcdf/4.6.3_1/include
*  Curl library               : 
*  Curl include dir           : /usr/local/opt/curl/include
*  GDAL library               : /Library/Frameworks/gdal.framework/Versions/Current/unix/lib/libgdal.dylib
*  GDAL include dir           : /Library/Frameworks/gdal.framework/Versions/Current/unix/include
*  FFTW library               : /usr/local/lib/libfftw3f.dylib
*  FFTW threads library       : /usr/local/lib/libfftw3f_threads.dylib
*  FFTW include dir           : /usr/local/include
*  Accelerate Framework       : /System/Library/Frameworks/Accelerate.framework
*  Regex support              : PCRE (/usr/local/Cellar/pcre/8.43/lib/libpcre.dylib)
*  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       : disabled
*  Build generator            : Unix Makefiles
*  Build mode                 : shared
*  Build GMT core             : always [libgmt.dylib]
*  Build PSL library          : always [libpostscriptlight.dylib]
*  Build GMT supplements      : yes [supplements.so]
*  Build GMT for developers   : yes
*  Build proto supplements    : none
*  Build module links         : no
*  Found Ghostscript (gs)     : yes (9.50)
*  Found GraphicsMagick (gm)  : yes (1.3.33)
*  Found ffmpeg               : yes (4.2.1)
*  Found open                 : yes
*  Found ogr2ogr              : yes (2.4.1)
*  Found gdal_translate       : yes (2.4.1)
*
*  Locations:
*  Installing GMT in          : /usr/local/gmt
*  GMT_DATADIR                : /usr/local/gmt/share
* GMT_DOCDIR                 : /usr/local/gmt/share/doc
*  GMT_MANDIR                 : /usr/local/gmt/share/man
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/<user>/Computing/GMTdev/gmt/mbuild

cmake --build . -j24 runs without issues to 100%, the cmake --build . --target install as well - all is installed in /usr/local/gmt/.

If I now try and run gmt at the command line I get the following segmentation fault:

ERROR: Caught signal number 11 (Segmentation fault) at
0   libgmt.6.dylib                      0x000000010858c183 gmt_replace_backslash_in_path + 19
1   ???                                 0x0000000000000000 0x0 + 0
Stack backtrace:
0   libgmt.6.dylib                      0x0000000108515114 sig_handler + 580
1   libsystem_platform.dylib            0x00007fff52852f5a _sigtramp + 26
2   ???                                 0x00007ffee76f4ef0 0x0 + 140732781252336
3   libgmt.6.dylib                      0x0000000108641b1f gmt_begin + 2383
4   libgmt.6.dylib                      0x0000000108524e53 GMT_Create_Session + 755
5   gmt                                 0x000000010850a783 main + 307
6   libdyld.dylib                       0x00007fff52544015 start + 1
7   ???                                 0x0000000000000001 0x0 + 1

If set (GMT_ENABLE_OPENMP TRUE) then I get the following error during compilation:

/Users/<user>/Computing/GMTdev/gmt/src/grdlandmask.c:649:2: error: condition of OpenMP for loop must be a relational comparison
      ('<', '<=', '>', or '>=') of loop variable 'row'
        gmt_M_grd_loop (GMT, Grid, row, col, ij) {      /* Turn levels into mask values */
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/<user>/Computing/GMTdev/gmt/src/gmt_grd.h:165:40: note: expanded from macro 'gmt_M_grd_loop'
#define gmt_M_grd_loop(C,G,row,col,ij) gmt_M_row_loop(C,G,row) gmt_M_col_loop(C,G,row,col,ij)
                                       ^~~~~~~~~~~~~~~~~~~~~~~
/Users/<user>/Computing/GMTdev/gmt/src/gmt_grd.h:163:47: note: expanded from macro 'gmt_M_row_loop'
#define gmt_M_row_loop(C,G,row) for (row = 0; (int)row < (int)G->header->n_rows; row++)
                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/gmtlib.dir/grdlandmask.c.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/CMakeFiles/gmtlib.dir/all] Error 2
make: *** [all] Error 2

Have also tried the release v6 dmg and this is the output I get opening GMT6.app:

politbuero:~ <user>$ /bin/bash "/Applications/GMT-6.0.0.app/Contents/MacOS/GMT-6.0.0"  GMT_PROMPT
ERROR: Caught signal number 11 (Segmentation fault) at
0   libgmt.6.0.0.dylib                  0x000000010be82294 gmt_replace_backslash_in_path + 4
1   ???                                 0x0000000000000000 0x0 + 0
Stack backtrace:
0   libgmt.6.0.0.dylib                  0x000000010be026f7 sig_handler + 583
1   libsystem_platform.dylib            0x00007fff52852f5a _sigtramp + 26
2   ???                                 0x00007ffee3e05d10 0x0 + 140732721552656
3   libgmt.6.0.0.dylib                  0x000000010bf4036f gmt_begin + 2511
4   libgmt.6.0.0.dylib                  0x000000010be12da2 GMT_Create_Session + 770
5   gmt                                 0x000000010bdfa70f main + 319
6   libdyld.dylib                       0x00007fff52544015 start + 1
7   ???                                 0x0000000000000002 0x0 + 2
ERROR: Caught signal number 11 (Segmentation fault) at
0   libgmt.6.0.0.dylib                  0x0000000101bbd294 gmt_replace_backslash_in_path + 4
1   ???                                 0x0000000000000000 0x0 + 0
Stack backtrace:
0   libgmt.6.0.0.dylib                  0x0000000101b3d6f7 sig_handler + 583
1   libsystem_platform.dylib            0x00007fff52852f5a _sigtramp + 26
2   ???                                 0x00007ffeee0cabe0 0x0 + 140732892228576
3   libgmt.6.0.0.dylib                  0x0000000101c7b36f gmt_begin + 2511
4   libgmt.6.0.0.dylib                  0x0000000101b4dda2 GMT_Create_Session + 770
5   gmt                                 0x0000000101b3570f main + 319
6   libdyld.dylib                       0x00007fff52544015 start + 1
7   ???                                 0x0000000000000001 0x0 + 1
Note 1: If you want to use GMT outside of this terminal or in scripts, then follow these steps:
        a) export GMTHOME=/Applications/GMT-6.0.0.app/Contents/Resources
        b) add $GMTHOME/bin to your path
        c) export PROJ_LIB=$GMTHOME/share/proj6
        d) export MAGICK_CONFIGURE_PATH=$GMTHOME/lib/GraphicsMagick-1.3.33/config
Note 2: GMT may use Ghostscript, GraphicsMagick, FFmpeg, and GDAL executables; see
        /Applications/GMT-6.0.0.app/Contents/Resources/share/Licenses for details.

Any ideas what could cause this? On my MacBook Pro (also running High Sierra) all works like a charm without issues.

Cheers,
Christian

Hi Christian-

I suspect some environmental differences yields a NULL path to someting and the gmt_replace_backslash_in_path function does not check if that is the case. I have pushed a fix for this to the repo, but you can test this in the mean time. Please edit gmt_io.c, find that function, and add this line before the loop:

if (dir == NULL) return;	/* No can do */

then compile and try again.

Hi Paul,

thanks - the segfault is gone following your change suggestion but I now get:

Assertion failed: (string != NULL), function gmt_strrepc, file /Users/<user>/Computing/GMTdev/gmt/src/common_string.c, line 145.
Abort trap: 6

Cheers,
Christian

It would seem on this Mac there are lots of environmental parameters that are simply not set and are NULL, which is unusual and perhaps unexpected. As far as we know, you are the only one who has this issue. Permission troubles? Anything odd with the account?

Thanks Paul - will investigate more and check perms/env parameters again and maybe try with a fresh account.

Christian

Just a short update on this - I managed to compile GMT6 and can run the programs w/o problems using a newly setup account on the machine - so you were right, Lord Vader, on the env parameters. Thanks again for the hint in that direction.

Apology accepted, Captain Needa.