英文:
Can't compile an OCaml program that uses sqlite3 module using dune
问题
我想测试OCaml中的Sqlite3绑定。
我已经使用opam下载了适当的包,它在使用utop时可以正常工作。
我已经像这样测试过了:
#use "topfind";;
#require "sqlite3";;
#show Sqlite3;;
open Sqlite3
let db = db_open "yolo";;
let _ = db_close db;;
问题是,我无法在使用dune编译的程序中使用相同的模块。以下是我尝试编译的确切代码:
(main.ml文件的内容)
let _ = Sqlite3.sqlite_version ();;
(dune文件的内容)
(executable
(name main)
(libraries sqlite3)
)
当我尝试使用dune build编译它时,我得到了Unbound value Sqlite3.sqlite_version。
这不会发生在其他包中(我检查了yojson,它按预期工作)。
编辑:值得注意的是,在.ml文件中打开Sqlite3模块(即open Sqlie3)是可以的。只是使用其中的任何函数会导致错误。
英文:
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.
答案1
得分: 2
解决方法非常简单。
不要将您的项目命名为您想在其中使用的库的相同名称。
我使用 dune init proj sqlite3 创建了一个名为 "sqlite3" 的项目,因此它自动为同名的库生成了一个样板。
将其命名为其他任何名称都可以解决问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论