caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Building pcre-ocaml on OCaml 3.11.0 on MinGW
@ 2009-02-20 14:28 David Allsopp
  2009-02-20 19:07 ` [Caml-list] " Gerd Stolpmann
  2009-04-23  9:30 ` Alain Frisch
  0 siblings, 2 replies; 5+ messages in thread
From: David Allsopp @ 2009-02-20 14:28 UTC (permalink / raw)
  To: OCaml List

[-- Attachment #1: Type: text/plain, Size: 4323 bytes --]

I've just had an enlightening few hours getting pcre-ocaml to compile under
Windows (I tried a few years ago and, very lazily, just gave up). I've
managed to get it to work but I'm wondering whether anyone else has done
this and, if so, whether they can explain/confirm/correct a couple of the
steps involved. I'm very much indebted to Alain Frisch's instructions for
building PCRE under OCaml 3.10.0 which are part of the CDuce distribution or
I would've been completely at sea with this!

The main thing that's got me puzzled is the renaming of libpcre.dll.a and
libpcre.a that I have to do to get the thing to link.

Note that I'm building the "official" way - so MinGW running within Cygwin.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++
Building pcre for MinGW
  (Ensure that Cygwin's PCRE libraries are *not* installed)
  Unpacked PCRE 7.8
  ./configure --prefix="C:/Dev/OCaml" \          # set to install PCRE
              --includedir="C:/Dev/OCaml/lib" \  # to my OCaml tree.
              --disable-cpp \                    # from Alain's
instructions.
              --enable-utf8 \                    # Similarly.
              --build=mingw32 \                  # MinGW, not Cygwin build
              CC="gcc -mno-cygwin"               # Necessary to ensure that
                                                 # autoconf detects the
correct
                                                 # library and include dirs 
                                                 # when querying gcc (CFLAGS
                                                 # won't work here)
  make
  make install

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++
Building pcre-ocaml
  (Note that with older (< 0.14) versions of flexlink, the linker errors
noted doesn't show up and the resulting library is broken)
  Unpacked pcre-ocaml 5.15.1
  Edit pcre-ocaml-release-5.15.1/Makefile.conf to contain:
    export LIBDIRS := C:/Dev/OCaml/lib # Location of PCRE
    export MINGW=1                     # MinGW build
    export CC=gcc                      # Or you get lots of errors!
  patch -p0 -i pcre-ocaml-release-5.15.1.patch # (attached)

  The patch "fixes" two things in OCamlMakefile
    a) It causes the ocamlc -where check to pass the result through cygpath.
My OCAMLLIB variable is correctly set (for Windows) as C:\Dev\OCaml\lib and
Cygwin configure scripts should generally respect that (build in Cygwin, run
in Windows so OCAMLLIB is a Windows environment variable...). I've been lazy
though and not done the same thing for the camlp4 -where test...
    b) It adds a simple check for OCaml 3.11 (it would be better if it did a
>= 3.11 check but I haven't bothered to bring up the GNU make info pages to
check the syntax for doing that!) and uses ocamlmklib instead of manually
building the stub libraries if OCaml 3.11 is found - the manual build
instructions included in OCamlMakefile are for 3.10 and earlier and so don't
work (i.e. non-flexlink linking)

  OK, so at this stage it looks as though we should be ready to build. But
if I run make (with flexlink 0.14 or later) then I get the following errors
(compiling with flexlink 0.13 works, but the resulting library is broken):

ocamlmklib -LC:/Dev/OCaml/lib -o pcre_stubs  pcre_stubs.o -lpcre
c:\Users\DRA\AppData\Local\Temp\dyndll8e6a10.o:pcre_stubs.c:(.text+0x205):
undefined reference to `__imp__pcre_callout'
[and several more missing __imp__pcre_... messages]

  The problem is in C:\Dev\OCaml\lib, it appears. In there are libpcre.a,
libpcre.dll.a and libpcre.la. If I rename libpcre.a to libpcre.old.a and
then libpcre.dll.a to libpcre.a then the build works and the resulting
library builds. As far as I can tell, this is something to do with libtool
but I know very little about this - is the inability of the library to link
without renaming these files something to do with using flexlink as the
linker? If I link a test program in C using -lpcre then it works - but is
that because gcc knows how to read .la files and looks for the libpcre.dll.a
file correctly?

  However, once this is followed through, the library does correctly build
and install - and the examples all seem to be working. So, finally, it's
cheerio to the Str module for me :o)

  Any pointers appreciated!


David

[-- Attachment #2: pcre-ocaml-release-5.15.1.patch --]
[-- Type: application/octet-stream, Size: 1655 bytes --]

diff -Naur pcre-ocaml-release-5.15.1/OCamlMakefile pcre-ocaml-release-5.15.1.new/OCamlMakefile
--- pcre-ocaml-release-5.15.1/OCamlMakefile	2008-11-29 05:30:56.000000000 +0000
+++ pcre-ocaml-release-5.15.1.new/OCamlMakefile	2009-02-20 09:55:37.659000000 +0000
@@ -352,11 +352,20 @@
 export OCAMLMAKEFILE
 
 ifndef OCAMLLIBPATH
+ifdef WIN32
+  OCAMLLIBPATH := \
+    $(shell cygpath -u `$(OCAMLC) 2>/dev/null -where` || echo /cygdrive/c/ocamlmgw)
+else
   OCAMLLIBPATH := \
     $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml)
 endif
+endif
 export OCAMLLIBPATH
 
+ifeq ($(shell ocamlc -config | fgrep "version: 3.11" > /dev/null && echo 1), 1)
+	OCAML311 := 1
+endif
+
 ifndef OCAML_LIB_INSTALL
   OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib
 endif
@@ -481,7 +490,12 @@
 endif
 
 ifdef WIN32
+# @@DRA Not sure that this shouldn't always be dll$(CLIB_BASE).dll?
+ifdef OCAML311
+DLLSONAME := dll$(CLIB_BASE).dll
+else
 DLLSONAME := $(CLIB_BASE).dll
+endif
 else
 DLLSONAME := dll$(CLIB_BASE).so
 endif
@@ -897,12 +911,19 @@
 
 ifndef STATIC
 ifdef MINGW
+ifdef OCAML311
+$(DLLSONAME):		$(OBJ_LINK)
+			$(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \
+				-o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) $(CFRAMEWORKS:%=-framework %) \
+				$(OCAMLMKLIB_FLAGS)
+else
 $(DLLSONAME):		$(OBJ_LINK)
 			$(CC) $(CFLAGS) $(CFLAGS_WIN32) $(OBJ_LINK) -shared -o $@ \
 			-Wl,--whole-archive $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/lib%.a))) \
 			 $(OCAMLLIBPATH)/ocamlrun.a \
 			-Wl,--export-all-symbols \
 			-Wl,--no-whole-archive
+endif
 else
 ifdef MSVC
 $(DLLSONAME):		$(OBJ_LINK)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Building pcre-ocaml on OCaml 3.11.0 on MinGW
  2009-02-20 14:28 Building pcre-ocaml on OCaml 3.11.0 on MinGW David Allsopp
@ 2009-02-20 19:07 ` Gerd Stolpmann
  2009-04-23  9:30 ` Alain Frisch
  1 sibling, 0 replies; 5+ messages in thread
From: Gerd Stolpmann @ 2009-02-20 19:07 UTC (permalink / raw)
  To: David Allsopp; +Cc: OCaml List

GODI includes now MinGW support, and pcre is among the actually working
packages. Just take it, or look there for how the build is done.

Note that you should take GODI for 3.10 because there is still a bug in
the 3.11 version.

Gerd

Am Freitag, den 20.02.2009, 14:28 +0000 schrieb David Allsopp:
> I've just had an enlightening few hours getting pcre-ocaml to compile under
> Windows (I tried a few years ago and, very lazily, just gave up). I've
> managed to get it to work but I'm wondering whether anyone else has done
> this and, if so, whether they can explain/confirm/correct a couple of the
> steps involved. I'm very much indebted to Alain Frisch's instructions for
> building PCRE under OCaml 3.10.0 which are part of the CDuce distribution or
> I would've been completely at sea with this!
> 
> The main thing that's got me puzzled is the renaming of libpcre.dll.a and
> libpcre.a that I have to do to get the thing to link.
> 
> Note that I'm building the "official" way - so MinGW running within Cygwin.
> 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> +++
> Building pcre for MinGW
>   (Ensure that Cygwin's PCRE libraries are *not* installed)
>   Unpacked PCRE 7.8
>   ./configure --prefix="C:/Dev/OCaml" \          # set to install PCRE
>               --includedir="C:/Dev/OCaml/lib" \  # to my OCaml tree.
>               --disable-cpp \                    # from Alain's
> instructions.
>               --enable-utf8 \                    # Similarly.
>               --build=mingw32 \                  # MinGW, not Cygwin build
>               CC="gcc -mno-cygwin"               # Necessary to ensure that
>                                                  # autoconf detects the
> correct
>                                                  # library and include dirs 
>                                                  # when querying gcc (CFLAGS
>                                                  # won't work here)
>   make
>   make install
> 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> +++
> Building pcre-ocaml
>   (Note that with older (< 0.14) versions of flexlink, the linker errors
> noted doesn't show up and the resulting library is broken)
>   Unpacked pcre-ocaml 5.15.1
>   Edit pcre-ocaml-release-5.15.1/Makefile.conf to contain:
>     export LIBDIRS := C:/Dev/OCaml/lib # Location of PCRE
>     export MINGW=1                     # MinGW build
>     export CC=gcc                      # Or you get lots of errors!
>   patch -p0 -i pcre-ocaml-release-5.15.1.patch # (attached)
> 
>   The patch "fixes" two things in OCamlMakefile
>     a) It causes the ocamlc -where check to pass the result through cygpath.
> My OCAMLLIB variable is correctly set (for Windows) as C:\Dev\OCaml\lib and
> Cygwin configure scripts should generally respect that (build in Cygwin, run
> in Windows so OCAMLLIB is a Windows environment variable...). I've been lazy
> though and not done the same thing for the camlp4 -where test...
>     b) It adds a simple check for OCaml 3.11 (it would be better if it did a
> >= 3.11 check but I haven't bothered to bring up the GNU make info pages to
> check the syntax for doing that!) and uses ocamlmklib instead of manually
> building the stub libraries if OCaml 3.11 is found - the manual build
> instructions included in OCamlMakefile are for 3.10 and earlier and so don't
> work (i.e. non-flexlink linking)
> 
>   OK, so at this stage it looks as though we should be ready to build. But
> if I run make (with flexlink 0.14 or later) then I get the following errors
> (compiling with flexlink 0.13 works, but the resulting library is broken):
> 
> ocamlmklib -LC:/Dev/OCaml/lib -o pcre_stubs  pcre_stubs.o -lpcre
> c:\Users\DRA\AppData\Local\Temp\dyndll8e6a10.o:pcre_stubs.c:(.text+0x205):
> undefined reference to `__imp__pcre_callout'
> [and several more missing __imp__pcre_... messages]
> 
>   The problem is in C:\Dev\OCaml\lib, it appears. In there are libpcre.a,
> libpcre.dll.a and libpcre.la. If I rename libpcre.a to libpcre.old.a and
> then libpcre.dll.a to libpcre.a then the build works and the resulting
> library builds. As far as I can tell, this is something to do with libtool
> but I know very little about this - is the inability of the library to link
> without renaming these files something to do with using flexlink as the
> linker? If I link a test program in C using -lpcre then it works - but is
> that because gcc knows how to read .la files and looks for the libpcre.dll.a
> file correctly?
> 
>   However, once this is followed through, the library does correctly build
> and install - and the examples all seem to be working. So, finally, it's
> cheerio to the Str module for me :o)
> 
>   Any pointers appreciated!
> 
> 
> David
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Building pcre-ocaml on OCaml 3.11.0 on MinGW
  2009-02-20 14:28 Building pcre-ocaml on OCaml 3.11.0 on MinGW David Allsopp
  2009-02-20 19:07 ` [Caml-list] " Gerd Stolpmann
@ 2009-04-23  9:30 ` Alain Frisch
  2009-04-23 10:34   ` Gerd Stolpmann
  2009-04-23 11:11   ` David Allsopp
  1 sibling, 2 replies; 5+ messages in thread
From: Alain Frisch @ 2009-04-23  9:30 UTC (permalink / raw)
  To: David Allsopp; +Cc: OCaml List

Hi David,

David Allsopp wrote:
> I've just had an enlightening few hours getting pcre-ocaml to compile under
> Windows
 >...
> The main thing that's got me puzzled is the renaming of libpcre.dll.a and
> libpcre.a that I have to do to get the thing to link.

Thanks for investigating this issue!  The current SVN version of 
flexlink prefers XXX.dll.a over XXX.a.  We will see whether it solves 
more problems than it creates...  Of course, it is always possible to 
pass explicitly the complete file name instead of -lXXX.

To build and use ocaml-pcre, I've had to remove the "-I /usr/include" 
from this line in OCamlMakefile:

   CFLAGS_WIN32 := -mno-cygwin -I /usr/include

Otherwise, Cygwin's headers are used instead of mingw's ones (in 
/usr/include/mingw), and we get a dependency e.g. to the Cygwin symbol 
_ctype_ which is not available on mingw. Have you had to do something 
similar?


Alain


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Building pcre-ocaml on OCaml 3.11.0 on MinGW
  2009-04-23  9:30 ` Alain Frisch
@ 2009-04-23 10:34   ` Gerd Stolpmann
  2009-04-23 11:11   ` David Allsopp
  1 sibling, 0 replies; 5+ messages in thread
From: Gerd Stolpmann @ 2009-04-23 10:34 UTC (permalink / raw)
  To: Alain Frisch; +Cc: David Allsopp, OCaml List


Am Donnerstag, den 23.04.2009, 11:30 +0200 schrieb Alain Frisch:
> Hi David,
> 
> David Allsopp wrote:
> > I've just had an enlightening few hours getting pcre-ocaml to compile under
> > Windows
>  >...
> > The main thing that's got me puzzled is the renaming of libpcre.dll.a and
> > libpcre.a that I have to do to get the thing to link.
> 
> Thanks for investigating this issue!  The current SVN version of 
> flexlink prefers XXX.dll.a over XXX.a.  We will see whether it solves 
> more problems than it creates...  Of course, it is always possible to 
> pass explicitly the complete file name instead of -lXXX.
> 
> To build and use ocaml-pcre, I've had to remove the "-I /usr/include" 
> from this line in OCamlMakefile:
> 
>    CFLAGS_WIN32 := -mno-cygwin -I /usr/include
> 
> Otherwise, Cygwin's headers are used instead of mingw's ones (in 
> /usr/include/mingw), and we get a dependency e.g. to the Cygwin symbol 
> _ctype_ which is not available on mingw. Have you had to do something 
> similar?

I can confirm this. I also got an error about _ctype_, and could solve
this by removing -I /usr/include.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] Building pcre-ocaml on OCaml 3.11.0 on MinGW
  2009-04-23  9:30 ` Alain Frisch
  2009-04-23 10:34   ` Gerd Stolpmann
@ 2009-04-23 11:11   ` David Allsopp
  1 sibling, 0 replies; 5+ messages in thread
From: David Allsopp @ 2009-04-23 11:11 UTC (permalink / raw)
  To: 'Alain Frisch'; +Cc: 'OCaml List'

> Hi David,
> 
> David Allsopp wrote:
> > I've just had an enlightening few hours getting pcre-ocaml to compile
> under
> > Windows
>  >...
> > The main thing that's got me puzzled is the renaming of libpcre.dll.a
> and
> > libpcre.a that I have to do to get the thing to link.
> 
> Thanks for investigating this issue!  The current SVN version of
> flexlink prefers XXX.dll.a over XXX.a.  We will see whether it solves
> more problems than it creates...  Of course, it is always possible to
> pass explicitly the complete file name instead of -lXXX.

Marvellous - I'll have a play when I have a spare minute <sigh>

> To build and use ocaml-pcre, I've had to remove the "-I /usr/include"
> from this line in OCamlMakefile:
> 
>    CFLAGS_WIN32 := -mno-cygwin -I /usr/include
> Otherwise, Cygwin's headers are used instead of mingw's ones (in
> /usr/include/mingw), and we get a dependency e.g. to the Cygwin symbol
> _ctype_ which is not available on mingw. Have you had to do something
> similar?

I last built with 5.15.1 which didn't have this line (just -mno-cygwin) but
I see that I'm behind (and Gerd's confirmed the problem, anyhow...)


David


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-04-23 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-20 14:28 Building pcre-ocaml on OCaml 3.11.0 on MinGW David Allsopp
2009-02-20 19:07 ` [Caml-list] " Gerd Stolpmann
2009-04-23  9:30 ` Alain Frisch
2009-04-23 10:34   ` Gerd Stolpmann
2009-04-23 11:11   ` David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).