如何使用自定义模块进行编译
我正在尝试用 2 个 .ml 编译一个项目,其中一个是遵循此格式的模块
module Mymodule =
struct
...
end;;
我还为 myModule 创建了一个 .mli
module Mymodule =
sig
...
end
但现在当我在 main.ml 中调用 Mymodule.myfunction 时,我得到 "Unbound值 Mymodule.myfunction"
。
这是我的 makefile(我也有标准的 OcamlMakeFile):
RESULT= result
SOURCES= Mymodule.ml main.ml
LIBS= bigarray sdl sdlloader sdlttf sdlmixer
INCDIRS= +sdl
include OCamlMakefile
我搜索并尝试了一些东西,但没有任何效果:(
感谢您的回答,我按照您链接的教程进行操作,但现在我遇到了 SDL 链接问题:
File "testsdl_2.ml", line 1, characters 0-1:
Error: No implementations provided for the following modules:
Sdl referenced from testsdl_2.cmx
Sdlloader referenced from testsdl_2.cmx
Sdlvideo referenced from testsdl_2.cmx
并且我' m 使用这一行来编译:
ocamlopt -I +sdl -o testsdl mymodule.cmx main.ml
I'm trying to compile a project with 2 .ml and one of them is a module follwing this format
module Mymodule =
struct
...
end;;
I also created a .mli for myModule
module Mymodule =
sig
...
end
But now when I call Mymodule.myfunction in main.ml, I get "Unbound value Mymodule.myfunction"
.
Here is my makefile (I also have the standard OcamlMakeFile) :
RESULT= result
SOURCES= Mymodule.ml main.ml
LIBS= bigarray sdl sdlloader sdlttf sdlmixer
INCDIRS= +sdl
include OCamlMakefile
I searched and tried some things but nothing is working :(
Thanks for your answer, I followed the tutorial you linked but now I've a problem with SDL linking:
File "testsdl_2.ml", line 1, characters 0-1:
Error: No implementations provided for the following modules:
Sdl referenced from testsdl_2.cmx
Sdlloader referenced from testsdl_2.cmx
Sdlvideo referenced from testsdl_2.cmx
and I'm using this line to compile:
ocamlopt -I +sdl -o testsdl mymodule.cmx main.ml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
每个 ml 源文件已经代表一个模块(名称等于文件名)。
仔细阅读有关模块的 ocaml 教程。
Each ml source file already represents a module (with the name equal to the name of the file).
Read ocaml tutorial on modules carefully.
为了扩大 ygrek 的答案,通过在名为 Mymodule.ml 的文件中声明名为 Mymodule 的模块,您将创建一个名为 Mymodule.Mymodule 的模块。您很可能只想删除 .ml 和 .mli 文件中的
module Mymodule
包装器,然后事情就会按您的预期进行。本质上,OCaml 为每个源文件免费提供一层模块包装。To enlarge a little on ygrek's answer, by declaring a module named Mymodule inside a file named Mymodule.ml, you are creating a module named Mymodule.Mymodule. Most likely you just want to remove the
module Mymodule
wrappers in the .ml and .mli files and then things will work as you expect. In essence, OCaml gives you one layer of module wrapping for free with each source file.我找到了解决方案:)
您必须更改所使用的库中的正确文件“META”。就我而言,必须通过添加以下行来更改库
odepack
中的 META 文件之后,必须对 Makefile 进行细微修改。该行
修改为
错误
此修改避免了当我们定义同一个库两次或多次时出现的 。在我的例子中,
Bigarray
库足以包含Unix
库。I found the solution :)
You have to change the right files "META" in the used libraries. In my case, the META file in the library
odepack
have to be changed by adding the following lineAfter that, a minor modification in the Makefile have to be done. The line
is modified to
This modification avoids the error
that occurs when we define the same library twice or more. The library
Bigarray
in my case is sufficient to include theUnix
library.