
Purpose
gridgen-c is a very useful library for generating two-dimensional orthogonal curvilinear grids. However, the original repository only supports building on Mac or Linux, and it cannot be built on Windows as is.
I have therefore modified it so that it can be built on Windows with MinGW, and I am publishing the result here.
I hope you find it useful.
Source Code
https://github.com/computational-sediment-hyd/gridgen-c_MinGW_Windows/
How to Build
Recommended: MSYS2 MinGW Shell
Install MSYS2, open the MSYS2 MinGW 64-bit shell, and run:
pacman -S --needed mingw-w64-x86_64-gcc make
cd gridgen
./configure
make
make lib # libgridgen.a
make shlib # libgridgen.dll (+ libgridgen.dll.a import library)
configure has already been regenerated with autoconf 2.69/2.71, so autoconf is not required.
Run autoconf -o configure configure.ac only if you edit configure.ac.
Without MSYS2 (plain cmd.exe + MinGW-w64)
A route that uses neither sh nor configure is also provided:
copy config.h.mingw config.h
mingw32-make -f makefile.mingw
mingw32-make -f makefile.mingw lib
mingw32-make -f makefile.mingw shlib
Source Code Changes (4 items)
Why the build fails
triangle.cdepends unconditionally on<sys/time.h>/gettimeofday()→NO_TIMERis now defined automatically on Windows (on 32-bit x86,CPU86is also defined automatically and x87 is fixed to 53-bit precision).- The build system assumes Unix →
configure.inwas rewritten asconfigure.ac, with host detection viaAC_CANONICAL_HOST.EXEEXT(.exe),SHLIB(dll),PICFLAG(empty), and--out-implibare switched accordingly.configurehas been regenerated with autoconf 2.71 (autoconf not required).
Why it breaks after building (the main issue)
- LLP64 bug in Triangle — pointers are stored in
unsigned long. On Win64,sizeof(long)==4, so every pointer loses its upper 32 bits and the program crashes immediately after startup (observed:page fault ... 0x00000000fe8d0050). Theunsigned longused in pointer arithmetic was replaced withuintptr_t(41 locations). key_find()ingridgen.crelies onftell()in text mode — on Windows text streams,ftell()does not return byte offsets (for the same LF file, Linux gives 11/25/31 while Windows gives 8/23/30).fseeklands in the middle of a key name, files with garbage names such ass sigmas.1are created, and no grid is written (while the exit code is still 0). Fixed by opening the parameter file in binary mode, plus CRLF support.
For details of the changes, see here.
The diff is also available as a patch here.
Sample
I have confirmed that grids can be generated with the gridgen.exe built as described above.
The sample dataset is available here.
gridgen prm.0

No comments:
Post a Comment