Hi everyone,

After a day or so messing with the GEOS source code, I've finally
managed to get GEOS HEAD to compile under MingW. Please find enclosed
the following patch to be applied to the current SVN tree.

I believe the problem with "multiple definition" errors was caused by
the fact that under Win32 DLLs must declare all their imports and
exports at compile time - hence MingW was automatically generating
import stubs for the inline functions when compiling with the gcc
-shared option. This caused the final link against inlines.o to fail
since the compiler had two definitions to contend with - those
automatically generated by the compiler and those in inlines.o.

The patch also addresses a problem with Charlie Savage's original patch
for the _finite() function - I had to wrap this in an "extern C"
definition for the compilation to work for me. If Charlie could verify
this on his compiler setup, that would be great.

Finally, even when this patch is applied, the final link causes the
MingW linker to segfault :( This is because libtool decides that the
number of object files is so large that it needs to complete the final
link in two stages, and my guess is that there is a bug somewhere in
MingW's ld.exe when used in this way. Fortunately there is a way to
alter libtool to persuade it to link the entire library in one go (see
below).

So to complete the compilation under MingW it is necessary to perform
the following steps:

        1) Obtain GEOS HEAD from SVN and apply the attached patch
        2) Run ./configure
        3) Run the following command to persuade libtool to use
        a longer command line for linking:

        mv libtool libtool.orig
        cat libtool.orig | sed 's/max_cmd_len=8192/max_cmd_len=16384/g'
        > libtool

        4) Execute the build using "make" or "make install"


I have applied the patch to both a Win32 tree and a Linux tree, and both
seem to compile without any problems. If Charlie and Mateusz can confirm
that I haven't broken their builds, that would be great.


Kind regards,

Mark.

Index: source/inlines.cpp
===================================================================
--- source/inlines.cpp	(revision 1949)
+++ source/inlines.cpp	(working copy)
@@ -23,6 +23,13 @@
 // Otherwise we'll end up with duplicated symbols
 #ifdef GEOS_INLINE
 
+// If using MingW with GEOS_INLINE to build a DLL then MingW's gcc
+// has already generated the stubs for the contents of this file. 
+// Hence we need to supress it to avoid "multiple definition" errors
+// during the final link phase
+#if defined(__MINGW32__) && !defined(DLL_EXPORT)
+
+
 // Undefine GEOS_INLINE so that .inl files
 // will be ready for an implementation file
 #undef GEOS_INLINE 
@@ -50,4 +57,7 @@
 #include <geos/noding/snapround/MCIndexSnapRounder.inl>
 #include <geos/noding/MCIndexNoder.inl>
 
+
+#endif // defined __MINGW32__ and !defined DLL_EXPORT
+
 #endif // defined GEOS_INLINE
Index: source/algorithm/HCoordinate.cpp
===================================================================
--- source/algorithm/HCoordinate.cpp	(revision 1949)
+++ source/algorithm/HCoordinate.cpp	(working copy)
@@ -30,9 +30,11 @@
 
 // For MingW builds with __STRICT_ANSI__ (-ansi)
 // See: http://geos.refractions.net/pipermail/geos-devel/2006-June/002342.html
-#if defined(__GNUC__) && defined(_WIN32)
+#if defined(__MINGW32__)
+extern "C" {
 int __cdecl _finite (double);
 #define finite(x) _finite(x)
+}
 #endif
 
 #ifndef GEOS_DEBUG
_______________________________________________
geos-devel mailing list
geos-devel@geos.refractions.net
http://geos.refractions.net/mailman/listinfo/geos-devel

Reply via email to