编译 OCaml 项目的简单方法是什么?
我正在玩弄 OCaml。我想知道如何构建一个 OCaml 项目的第一件事。现在,我只想要一些非常简单的东西,因为我刚刚学习。有人可以向我指出一个构建系统以及使用该构建系统的“hello world”类型示例吗?
I'm toying around with OCaml. The first thing I want to know how to do is build an OCaml project. Right now, I just want something stupidly simple since I'm just learning. Could anyone point me towards a build system along with a "hello world" type example for using that build system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
ocamlopt 是标准的本机代码编译器。典型的构建语法是:
您可以使用
ocamlc
来编译为字节码。一般来说,标准库已经包含在内。如果您使用的是 *nix 系统,并且想要包含 unix 库,您可以执行诸如
cmxa 文件是本机代码库、cma 文件是字节码库之类的操作。
对于更复杂的构建,可以使用 ocamlfind 程序来帮助定位库。您还可以使用 GNU make 和类似的工具。更多信息可以在此处找到。 这是一个关于使用 gmake 的页面。
这是一个不错的“程序员的第一个 Ocaml”页面。
这里是我在大学时参加的 Ocaml 课程的讲座页面。不过,不要试图向冈特教授寻求任何提示,如果没记错的话,她是一个邪恶的巨魔。
ocamlopt is the standard native-code compiler. Typical build syntax is:
You can use
ocamlc
to compile to bytecode instead.Generally the standard library is already included. If you're on a *nix system, and want to include, say, the unix library, you'd do something like
cmxa files are native code libs, cma files are bytecode libs.
For more complicated builds, theres the ocamlfind program that helps locate libaries. You can also use GNU make and similar tools. More info can be found here. This is a page about using gmake.
This is an ok "Coder's First Ocaml" page.
Here is the lectures page for the Ocaml class I took back in college. Don't try hitting up Professor Gunter for any tips, though, she was an evil troll if memory serves.
还有ocamlbuild。对于没有外部依赖项的简单项目,它很简单
There is also ocamlbuild. For the simple project without external dependencies it is as simple as
看看 Markus Mottle 的
ocaml-make
。该项目包括OCamlMakefile
。将其复制到源目录并创建一个Makefile
,例如:Have a look at
ocaml-make
by Markus Mottle. The project includesOCamlMakefile
. Copy this into your source directory and create aMakefile
, e.g.:您可能正在寻找ide。查看了解 OCAML IDE 吗?。
http://www.ocaml-tutorial.org/compiling_ocaml_projects 解释了编译基础知识。该页面底部有一个名为“自动构建系统”的部分,并链接到主题“使用 GNU make 进行编译”和“使用 Omake 进行编译”,两者都包含示例。
You're probably looking for an ide. Take a look at Know of an OCAML IDE?.
http://www.ocaml-tutorial.org/compiling_ocaml_projects explains the compilation basics. At the bottom of that page there's a section called
Automated build systems
and links to the topicsCompiling with GNU make
andCompiling with Omake
both including samples.您可能知道这一点,但以防万一您不知道,OCaml 包含一个 REPL,您可以使用它进行交互式编码,而无需编译。当您第一次学习时,它可能非常有用。
You probably know this, but just in case you don't, OCaml include a REPL that you can use to code interactively without needing to compile. It can be quite useful when you're first learning.
一个即将到来的项目是 OASIS,这是一个由 Sylvain Le Gall 开发的非常漂亮的构建系统。他在他的一系列 OCaml 项目中使用它,我也是如此。
An up-and-coming project is OASIS, a pretty nifty build system being developed by Sylvain Le Gall. He uses it in a bunch of his OCaml projects, so do I.
我还会为 Ocaml 添加另一个
Makefile
,我将其用于我的项目。Makefile
和示例用法可在 Ocaml 上获取网站。I would also add another
Makefile
for Ocaml, which I use for my projects.The
Makefile
and example usage are available on the Ocaml website.