简体   繁体   English

OCaml - 找不到graphics.cma

[英]OCaml - Cannot find graphics.cma

When loading the Graphics module in the toplevel, I get an error saying "Cannot find graphics.cma". 在顶层加载图形模块时,出现“无法找到graphics.cma”的错误。

I'm using OS X and I'm pretty sure I've installed OCaml correctly since I've been using it for about a month now. 我正在使用OS X,我很确定我已经正确安装了OCaml,因为我已经使用它大约一个月了。 So it seems that the Graphics module wasn't included in the OCaml package. 因此,似乎图形模块未包含在OCaml包中。

How can I fix this issue, or how can I install the Graphics module myself? 我该如何解决这个问题,或者我如何自己安装Graphics模块?

First of all, check Graphics is really installed. 首先,检查Graphics是否真的安装完毕。 This library is optional and therefore it may not be installed. 此库是可选的,因此可能未安装。 There are several ways to check but the following should work for any situation: 有几种方法可以检查,但以下内容适用于任何情况:

$ ls `ocamlc -where`/graphics*

If there is no file listed by the above command, Graphics is not installed and you have to reinstall OCaml compiler enabling Graphics. 如果上面的命令没有列出文件,则不安装Graphics,您必须重新安装启用Graphics的OCaml编译器。

If files like graphics.cma are there, then you have to show us how you try to compile your code with Graphics. 如果有像graphics.cma这样的文件,那么你必须告诉我们你是如何尝试使用Graphics编译代码的。 The best answer varies depending on how you compile: inside toplevel, hand compiling with ocamlc, or with some build tool like ocamlbuild. 最佳答案取决于您的编译方式:内部顶层,使用ocamlc手动编译,或使用某些构建工具(如ocamlbuild)。

The solution mostly depends on how are you compiling. 解决方案主要取决于您的编译方式。 If you're using ocamlbuild tool, the the following would be sufficient: 如果您正在使用ocamlbuild工具,则以下内容就足够了:

ocamlbuild -use-ocamlfind -pkg graphics my_program.native

Where my_program.native is your target. my_program.native是你的目标。 Note, you can try to omit the -use-ocamlfind flag. 注意,您可以尝试省略-use-ocamlfind标志。

In order to bring graphics to your toplevel, the easiest solution would be to use topfind: 为了将图形带到您的顶层,最简单的解决方案是使用topfind:

# #use "topfind";;
# #require "graphics";;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM