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
==============================================
-----------------------------------------------
SETUP
-----------------------------------------------
1. Download env script setup from http://www.libsdl.org/extras/win32/cross/
Run Script but do not install ADA (fails?). This builds gcc, binutils, etc.

2. Setup source in WIN_CROSS with cross-configure.sh and cross-make.sh scripts.
Also added env source file from http://ricardo.ecn.wfu.edu/~cottrell/cross-gtk/

3. Downloaded GTK stuff from http://www.gimp.org/~tml/gimp/win32/downloads.html
This includes zlib, png, jpeg, tiff, etc. 

4. Download various support files from

http://gnuwin32.sourceforge.net/packages.html

including libGSL, PdCurses (for GRASS), and libGW32C (required by png)

5. Unzipped above download files into install dir
(/usr/local/cross-tools/i386-mingw32)

6. Repaired GTK pkgconfig files in
/usr/local/cross-tools/i386-mingw32/lib/pkgconfig.
Ran following script to fix prefix line in *.pc files

#!/bin/sh
TARGET=/usr/local/cross-tools/i386-mingw32
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
done

7. Can now build GTK apps!!

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

../../cross-make.sh

../../cross-make.sh install

-------------------------------------------------------------
MB-System
-------------------------------------------------------------
1. Edit install_makefile and use LINUX define

2. Edit mr1pr_defines.h in mr1pr as change to following ...
#ifdef LINUX
#include
#include
#include
#include
#endif

3. Edit memalloc.c in mr1pr and comment out includes ...
/**
#include
#include
**/

4. Edit sapi.h in surf to pick up correct WIN32 includes
#include
#include 

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
structure
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 \
....
$(DLLWRAP) $(DLLWRAP_FLAGS) \
        --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 cross-configure.sh, 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 …

int
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)
{
        fclose(old);
        return -1;
}

while (1)
{
        c = fgetc(old);

        if (!feof(old) )
                fputc(c, new);
        else
                break;
}

fclose (new);
fclose (old);

return 0;
}

 

Categories: 

Company Logo

Tekmap Logo