How to compile ocaml to native code
Posted
by Indra Ginanjar
on Stack Overflow
See other posts from Stack Overflow
or by Indra Ginanjar
Published on 2010-04-20T04:39:13Z
Indexed on
2010/04/20
4:43 UTC
Read the original article
Hit count: 335
i'm really interested learning ocaml, it fast (they said it could be compiled to native code) and it's functional. So i tried to code something easy like enabling mysql event scheduler.
#load "unix.cma";;
#directory "+mysql";;
#load "mysql.cma";;
let db = Mysql.quick_connect
~user:"username"
~password:"userpassword"
~database:"databasename"();;
let sql =
Printf.sprintf "SET GLOBAL EVENT_SCHEDULER=1;"
in
(Mysql.exec db sql);;
It work fine on ocaml interpreter, but when i was trying to compile it to native (i'm using ubuntu karmic), neither of these command worked
ocamlopt -o mysqleventon mysqleventon.ml unix.cmxa mysql.cmxa
ocamlopt -o mysqleventon mysqleventon.ml unix.cma mysql.cma
i also tried
ocamlc -c mysqleventon.ml unix.cma mysql.cma
all of them resulting same message
File "mysqleventon.ml", line 1, characters 0-1:
Error: Syntax error
Then i tried to remove the "# load", so the code goes like this
let db = Mysql.quick_connect
~user:"username"
~password:"userpassword"
~database:"databasename"();;
let sql =
Printf.sprintf "SET GLOBAL EVENT_SCHEDULER=1;"
in
(Mysql.exec db sql);;
The ocamlopt resulting message
File "mysqleventon.ml", line 1, characters 9-28:
Error: Unbound value Mysql.quick_connect
I hope someone could tell me, where did i'm doing wrong.
© Stack Overflow or respective owner