You are here

MB-System Win32 Cross Compile Notes

One reason for developing the GTK+ MB-System interface was the need for a cross-platform interface to the MB-System mbio library. The GTK+ MB-System has been built for and run on a Windows® system. The software was cross-compiled on a Linux x32 system using the tools from MinGW.

The following are the brief notes kept for setting up the cross-compile environment, and building the MB-System mbio library and the GTK+ MB-System interface. These notes are from 2008, so some of the instructions may a out of date.

Cross Compile Setup Notes

  1. Download env script setup from
    Run Script but do not install ADA (fails?). This builds gcc, binutils, etc.
  2. Setup source in WIN_CROSS with and scripts. Also added env source file from
  3. Downloaded GTK stuff from
    This includes zlib, png, jpeg, tiff, etc.
  4. Download various support files from
    including libGSL, PdCurses (for GRASS), and libGW32C (required by png).
  5. Unzipped above download files into install dir
  6. Repaired GTK pkgconfig files in
    Ran following script to fix prefix line in *.pc files
    for f in *.pc ; do
       grep -v 'cross-tools' $f > $f.tmp
       cat head1 $f.tmp > $f.tmp2
       rm $f.tmp
       mv $f.tmp2 $f
  7. Can now build GTK apps!!


  1. To build DLL used ...
    ../../ --prefix=/usr/local/cross-tools/i386-mingw32/
    --enable-dll -disable-cxx --enable-shared --enable-c-only
    ../../ install


  1. Edit install_makefile and use LINUX define
  2. Edit mr1pr_defines.h in mr1pr as change to following ...
    #ifdef LINUX
  3. Edit memalloc.c in mr1pr and comment out includes ...
  4. Edit sapi.h in surf to pick up correct WIN32 includes
  5. Changed line 625 in sapi.h from u_char to mb_u_char
  6. Edit mb_read_init.c, mb_write_init.c, and mb_close.c in
    mbio to change includes as in #2
  7. Edit mb_esf.c and mbsys_surf.h and replace u_char with mb_u_char
  8. Edit mb_process.c and add "include winsock2.h" for gethostname def
  9. Edit src/mbaux/Makefile to remove references to xgr so xgraphics.c
    is not built
  10. Edit DSL includes to definition of interface to dsl_interface in
    Files are: mbsys_dsl.h, mbf_dsl120pf.h, mbf_dsl120sf.h.
    Edit Source files in mbio: mbsys_dsl.c, mbr_dsl120pf.c, mbr_dsl120sf.c
    to change struct member interface to dsl_interface. The "interface" definition
    must be defined somewhere else?
  11. To build libraries as DLL's add the following to each Makefile
    AS = i386-mingw32-as
    DLLWRAP = i386-mingw32-dllwrap
    DLLWRAP_FLAGS = --as=$(AS) --export-all --driver-name $(CC) -s
    then add build arg such as
    libmbio.dll: mb_format.o mb_error.o \
            --output-def libprob.def --implib $(LIBDIR)/libmbio.a \
            -o $@ $^ -lnetcdf -lmbgsf -lsapi -lmr1pr -lmbproj \
            -lxdr -lwsock32 -lws2_32
  12. After edit Makefile with link flags, etc run 'cross.make libmbio.dll'
    and copy DLL to lib directory.
  13. Build programs as required. I have built mbinfo, and mblist as a test.
  14. For GTK+ MB-System run, edit src/misc.c to comment
    out "sys/wait.h", and edit Makfile to remove "-L/usr/local/mbsystem/lib",
    -lmbxgr, and add libs from adove "-lxdr -lwsock32 -lws2_32". Without above
    libs program, will build and start, but cannot load data.

Windows® Issues

There are a few issues with using the mbio library on Windows®. One issue is the use of the system command. As an example mb_esf.c uses system to copy the esf file to a tmp file as backup when editing. This copy command will fail on windows. The system command can in this case be replaced with the following routine …

file_copy (char *orig_name, char *new_name)
FILE *old, *new;
int c;

if ( (old = fopen(orig_name, "rb") ) == NULL)
        return -1;

if ( (new = fopen(new_name, "wb") ) == NULL)
        return -1;

while (1)
        c = fgetc(old);

        if (!feof(old) )
                fputc(c, new);

fclose (new);
fclose (old);

return 0;