caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Building ocaml-mysql on Mac OS X
@ 2005-07-16 19:51 Ranjan Bagchi
  2005-07-17  1:46 ` [Caml-list] " Paul Snively
  0 siblings, 1 reply; 2+ messages in thread
From: Ranjan Bagchi @ 2005-07-16 19:51 UTC (permalink / raw)
  To: caml-list

Hi --

Curious if anyone has had luck buildling ocaml-mysql on OS X ( it  
seem to be fine on linux).

I had to mess with the Makefile so it would find the mysql libraries  
in /opt/local (I use darwin ports), and did the obvious things, but  
when I build a toplevel and try to bring in the mysql stuff I get the  
following error:

Ranjan-Bagchis-Computer:~/ocaml/foo ranjan$ ocamlfind mktop -o  
topmysql -package mysql -custom

Ranjan-Bagchis-Computer:~/ocaml/foo ranjan$ ./topmysql
         Objective Caml version 3.08.3

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
   #require "package";;      to load a package
   #list;;                   to list the available packages
   #camlp4o;;                to load camlp4 (standard syntax)
   #camlp4r;;                to load camlp4 (revised syntax)
   #predicates "p,q,...";;   to set these predicates
   Topfind.reset();;         to force that packages will be reloaded
   #thread;;                 to enable threads

- : unit = ()
# #require "mysql";;
/opt/local/lib/site-lib/mysql: added to search path
/opt/local/lib/site-lib/mysql/mysql.cma: loaded
The external function `db_connect' is not available

Any hints on getting this built successfully?

Thanks,

Ranjan Bagchi


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

* Re: [Caml-list] Building ocaml-mysql on Mac OS X
  2005-07-16 19:51 Building ocaml-mysql on Mac OS X Ranjan Bagchi
@ 2005-07-17  1:46 ` Paul Snively
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Snively @ 2005-07-17  1:46 UTC (permalink / raw)
  To: Ranjan Bagchi; +Cc: caml-list

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Ranjan,

On Jul 16, 2005, at 12:51 PM, Ranjan Bagchi wrote:

> Hi --
>
> Curious if anyone has had luck buildling ocaml-mysql on OS X ( it  
> seem to be fine on linux).
>
Funny you should ask: I just went through this process today, actually.

> I had to mess with the Makefile so it would find the mysql  
> libraries in /opt/local (I use darwin ports), and did the obvious  
> things, but when I build a toplevel and try to bring in the mysql  
> stuff I get the following error:
>
> Ranjan-Bagchis-Computer:~/ocaml/foo ranjan$ ocamlfind mktop -o  
> topmysql -package mysql -custom
>
> Ranjan-Bagchis-Computer:~/ocaml/foo ranjan$ ./topmysql
>         Objective Caml version 3.08.3
>
> # #use "topfind";;
> - : unit = ()
> Findlib has been successfully loaded. Additional directives:
>   #require "package";;      to load a package
>   #list;;                   to list the available packages
>   #camlp4o;;                to load camlp4 (standard syntax)
>   #camlp4r;;                to load camlp4 (revised syntax)
>   #predicates "p,q,...";;   to set these predicates
>   Topfind.reset();;         to force that packages will be reloaded
>   #thread;;                 to enable threads
>
> - : unit = ()
> # #require "mysql";;
> /opt/local/lib/site-lib/mysql: added to search path
> /opt/local/lib/site-lib/mysql/mysql.cma: loaded
> The external function `db_connect' is not available
>
This is because your stub library wasn't linked with the MySQL client  
library.

> Any hints on getting this built successfully?
>
Absolutely. I'll tell you what I did, and offer a suggestion as to  
what you'll likely have to do based on where your MySQL installation is.

First, I retrieved ocaml-mysql 1.0.3. Unfortunately, the  
OCamlMakefile it includes is fairly old, so I downloaded the current  
OCamlMakefile release as of today and replaced ocaml-mysql's with the  
new one.

My MySQL installation is from the .dmg from the MySQL.com site, which  
puts everything in the traditional place. Unfortunately, ocaml-mysql  
(and apparently lots of other MySQL client code) expects to be able  
to include headers of the form "#include <mysql/mysql.h>", so I had  
to "cd /usr/local/mysql/include; sudo ln -s . mysql" in order to have  
a "mysql/*.h" path. Your milage may vary depending upon your  
installation.

My first attempts to configure failed, and examining the config.log  
revealed that this was because of missing "compress" and "uncompress"  
functions, so I edited configure.in's "Checking for MySQL Library"  
section, the for... loop through the various possible library  
directories, to read:

test -f "$d/libmysqlclient.a" && LDFLAGS="-L$d -lz"

That is, I added the "-lz" link to the LDFLAGS to have it link with  
zlib, and then ran "autoreconf --install". Note that I had installed  
a recent autoconf/automake/libtool a few months back, on general  
principles (Apple, for some reason, consistently ships outdated  
autoconf/automake/libtools).

Now configuration worked, but "make" failed with:

ocamlmklib          \
                         -o mysql_stubs  mysql_stubs.o -lz - 
lmysqlclient \

/usr/bin/ld: can't locate file for: -lmysqlclient
collect2: ld returned 1 exit status
make[1]: *** [dllmysql_stubs.so] Error 2

No surprise there; I sure don't see any reference to /usr/local/mysql/ 
lib anywhere. Examining the generated Makefile revealed that LDFLAGS  
correctly has the -L/usr/local/mysql/lib, but examination of the  
OCamlMakefile revealed that the non-Windows DLLSONAME rule lacked a  
reference to LDFLAGS. I edited the rule to read:

$(DLLSONAME):           $(OBJ_LINK)
                         $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) $ 
(LDFLAGS) \
                                 -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:% 
=-l%) \
                                 $(OCAMLMKLIB_FLAGS)

That is, I added $(LDFLAGS) after $(CLIBFLAGS).

This resulted in "make" and "make opt" running to completion. "sudo  
make install" then put everything where it belongs. Then:

 >ocaml

         Objective Caml version 3.08.3

# #use "topfind";;
- - : unit = ()
Findlib has been successfully loaded. Additional directives:
   #require "package";;      to load a package
   #list;;                   to list the available packages
   #camlp4o;;                to load camlp4 (standard syntax)
   #camlp4r;;                to load camlp4 (revised syntax)
   #predicates "p,q,...";;   to set these predicates
   Topfind.reset();;         to force that packages will be reloaded
   #thread;;                 to enable threads

- - : unit = ()
# #require "mysql";;
/usr/local/lib/ocaml/site-lib/mysql: added to search path
/usr/local/lib/ocaml/site-lib/mysql/mysql.cma: loaded

Success.

Now for the additional steps that you'll almost certainly need:

In the AC_CHECKING(for MySQL library) section, you'll need to add / 
opt/local/mysql/lib or whatever the actual path to your MySQL client  
libraries is. Similarly, in the header section just below that,  
you'll need to add the path to your MySQL includes. Note that if your  
layout isn't of the form <path>/mysql/*.h, you'll need to perform a  
trick similar to the one I did, or edit the mysql_stubs.c file to  
remove the <mysql/...> part of the #include directives.

It bothers me a bit that I had to edit the current OCamlMakefile  
release to make this work, but I just couldn't see any way around it.  
At least it was just that and a minor fix to the configure.in script  
in the end.

> Thanks,
>
> Ranjan Bagchi
>
> _______________________________________________
> 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

Best regards,
Paul Snively

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iEYEARECAAYFAkLZuIwACgkQO3fYpochAqI6qQCgmy8kag4RW5IyTWtiavpOZHCZ
0r0AnRoPgvV3Y9XuLatgD/R3gGUICgv+
=v2+R
-----END PGP SIGNATURE-----


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

end of thread, other threads:[~2005-07-17  1:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-16 19:51 Building ocaml-mysql on Mac OS X Ranjan Bagchi
2005-07-17  1:46 ` [Caml-list] " Paul Snively

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).