0

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.

zajer
  • 649
  • 6
  • 17
  • Is your project just main.ml and this dune file? Nothing else in the directory? – Chris Jun 18 '23 at 14:52
  • There are other files. All of them were generated using `dune init proj sqlite` and then `dune init exe main`. I've modified dune and main file in the `sqlite` folder as described in the question. – zajer Jun 18 '23 at 15:04

1 Answers1

2

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.

zajer
  • 649
  • 6
  • 17