I wanted to test the Sqlite3 bindings in OCaml.
I have downloaded the appropriate package with opam
, it works fine using utop
.
I have tested it like this:
#use "topfind";;
#require "sqlite3";;
#show Sqlite3;;
open Sqlite3
let db = db_open "yolo";;
let _ = db_close db;;
The problem is I can't use the same module in a program compiled with dune. Here is the exact code I try to compile:
(content of main.ml
file)
let _ = Sqlite3.sqlite_version ();;
(content of dune
file)
(executable
(name main)
(libraries sqlite3)
)
When I try to compile it using dune build
I get Unbound value Sqlite3.sqlite_version
.
It does not happen with other packages (checked yojson
and it works as intended).
EDIT: It is worth noting that opening Sqlite3
(i.e. open Sqlie3
) module in an .ml file works. It just using any of the functions inside results in error.
The solution is very simple.
Do NOT name your project the same as a library you want to use in it.
I have created a project named "sqlite3" using dune init proj sqlite3
hence it automatically generated a boilerplate for a library named the same.
Naming it any other way solved the problem.