Cygwin64 bug suggested workaround for compiling GMT5

Added by Carl about 3 years ago

I have discovered and reported a bug to the cygwin developers in the lrint and llrint functions in the math.h library of cygwin64.
A workaround for compiling GMT5 which worked for me was to add the following line (which will hopefully soon become superfluous):

#define lrint(x) ((long int)(int)lrint(x))

to line 70 of GMT's common_math.h and line 134 of postscriptlight.c files.
After that gmt compiled without errors and all examples completed without errors.

This line can probably be improved by including an #if to test for "__CYGWIN__" and "__x86_64" or similar.

The bug in lrint means that the function returns an int when it should be returning a long int. The workaround type casts it back to a long int and should work unless extra the digits of the long int are needed.

The cygwin home folder should not have spaces in any part of its path.
—--—--—---
I installed cygwin64 from scratch downloading the netcdf, curl and gdal packages with the cygwin installer. I used the following instructions for installing GMT:

Install the following packages using the cygwin installer.

cmake, fftw, fftw-devel, gcc, g++, ghostscript, gv, libnetcdf7, libnetcdf-devel,
libpcre, libpcre-devel, make, openssh, subversion, xinit, zlib, zlib-devel

Set the environmental variable HDF5_DISABLE_VERSION_CHECK=2 by adding the following line to the '.bashrc' file in the cygwin home folder (Omitting this step will cause an error):
export HDF5_DISABLE_VERSION_CHECK=2

Download the latest stable GMT source code and extract the source codes into a folder.
In the GMT source folder, copy cmake/ConfigUserTemplate.cmake to cmake/ConfigUser.cmake and edit the file. For example (adapt to your local settings):

set (CMAKE_INSTALL_PREFIX "/GMT5/gmt-5.4.1")
set (GSHHG_ROOT "/GMT5/gshhg-gmt-2.3.6")
set (DCW_ROOT "/GMT5/dcw-gmt-1.1.2")

Build and install GMT:
cd <path to GMT>
mkdir build
cd build
cmake ..
make
make install

Set up the PATH environmental variables for GMT by adding the following line in '.bashrc' file in the cygwin home folder - for example:
export PATH=$PATH:/GMT5/gmt-5.4.1/bin

Good luck
Carl Fredrik


Replies (3)

RE: Cygwin64 bug suggested workaround for compiling GMT5 - Added by Paul about 3 years ago

Thanks, I have added this to r18343 under #defines for Cygwin and 64-bit.

RE: Cygwin64 bug suggested workaround for compiling GMT5 - Added by Carl about 3 years ago

Correcting myself:
There is a typo in my first message.
The bug in lrint(x) gives an unsigned int, not int as first written, and therefore gives the two's complement of the rounded value of x if x is negative.
e.g. lrint(-1.0) gives 4294967295, not -1 as it should.
(int)lrint(-1.0) gives -1, but lrint should return a long int. The workaround is therefore to use:
(long int)(int)lrint(-1.0), which also gives -1

RE: Cygwin64 bug suggested workaround for compiling GMT5 - Added by Paul about 3 years ago

Thanks, I added an URL to this forum note in the code. If you use Win10 then using the Microsoft bash for ubuntu would bypass all the cygwin issues for you entirely as it gives a complete Ubuntu installation.

(1-3/3)