未绑定模块Png-Png.load [英] Unbound module Png - Png.load

查看:58
本文介绍了未绑定模块Png-Png.load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试将png图像文件加载到OCaml中.我正在尝试使用Png.load函数,但是当我使用它时,OCaml给我错误:

I am currently trying to load a png image file into OCaml. I am trying to use the Png.load function but when I use it OCaml gives me the error:

未绑定模块Png merlin.

Unbound module Png merlin.

我已经下载了CamlImages.我正在使用

I have CamlImages downloaded. I am using

  • OCaml版本4.08.1
  • 摄像机版本5.0.1 而且我在

  • OCaml version 4.08.1
  • camlimages version 5.0.1 and I'm on

macOS Catalina版本10.15.1 .

我真的很感谢任何人能给我的帮助或任何信息.数周以来,我一直在努力解决此问题.

I'd really appreciate any help or any information anyone could give me. I've been trying to fix solve this issue for weeks.

推荐答案

要在OCaml中使用程序包,您必须执行以下两项操作:

To use a package in OCaml you have to perform two actions:

  1. 安装软件包
  2. 告诉您的构建系统以使用软件包

这是一个通用指南,由于OCaml是一个成熟的系统,有很多选项可供选择,包管理器和构建系统很多,因此细节可能会有所不同.我将从最普通的开始.

This is a general guideline, details may vary since OCaml is a mature system with many options to choose from, there are many package managers and lots of build systems. I will start with the most common.

如果您使用的是OCaml软件包管理器( opam ),则可以使用,例如

If you're using OCaml Package Manager (opam), then you can install your package using opam install <pkgname>, e.g.,

opam install camlimages

不要忘了用

eval $(opam env)

由于opam在本地安装软件包,因此您需要正确设置环境,以便您的构建系统可以看到它.这就是eval $(opam env)所做的.

as opam installs packages locally and you need to setup the environment correctly so that your build system can see it. This is what eval $(opam env) is doing.

OCamlBuild很古老,但是仍然退出了用于构建OCaml程序的流行工具.它非常易于使用,不会问太多问题.但是,它不适用于大型项目.假设您的应用程序主文件为app.ml,则构建命令非常简单

OCamlBuild is venerable but still quit popular tool for building OCaml programs. It is very easy to use and doesn't ask too many questions. It doesn't scale well to large projects though. Provided that your application main file is app.ml, the build command is very simple

ocamlbuild -pkg camlimages.all app.native

该命令将自动扫描并建立本地依赖关系,并将您的应用程序与camlimages包链接.您可以使用-pkgs标志(例如,

The command will automatically scan the local dependencies and build them, as well as link your application with the camlimages package. You can add more packages, using the -pkgs flag, e.g.,

ocamlbuild -pkgs camlimages.all,core_kernel app.native

由于OCamlBuild正在扫描您的文件夹中的文件,因此您应该为每个新文件夹创建一个新的新文件夹. OCamlBuild不喜欢您文件夹中的任何剩余或垃圾文件.它甚至可能抱怨它们,并创建一个脚本来删除它们.

Since OCamlBuild is scanning your folder for files you should create a fresh new folder for each new folder. OCamlBuild doesn't like any leftover or junk files in your folder. It may even complain about them and create a script that will remove them.

Merlin是其自己的构建系统,因此它也需要一些设置.最简单的方法是在项目的顶部文件夹中创建.merlin文件,并为每个要使用的包添加PKG <pkgname>行,例如

Merlin is a build system of its own, so it also needs some setup. The easiest way is to create a .merlin file in the top folder of your project and for each package that you want to use add a line PKG <pkgname>, e.g.,

 PKG camlimages.all

包装与图书馆

在OCaml中,程序包是库的集合.通常,构成一个程序包的库的名称可能与该程序包的名称不同.这通常会引起很多混乱.对于camlimages,我们有一个camlimages程序包,其中包含很多库,例如

Packages vs Libraries

In OCaml a package is a collection of libraries. In general, the names of libraries that constitute a package may be different from the name of the package. This usually raises a lot of confusion. In the case of camlimages, we have a package camlimages which has a lot of libraries, e.g.,

$ ocamlfind list | grep camlimages
camlimages          (version: 4.2.6)
camlimages.all      (version: 4.2.6)
camlimages.all_formats (version: 4.2.6)
camlimages.core     (version: 5.0.1)
camlimages.exif     (version: 5.0.1)
camlimages.freetype (version: 5.0.1)
camlimages.gif      (version: 5.0.1)
camlimages.graphics (version: 5.0.1)
camlimages.jpeg     (version: 5.0.1)
camlimages.png      (version: 5.0.1)
camlimages.tiff     (version: 5.0.1)
camlimages.xpm      (version: 5.0.1)

要弄清楚这些子库之间的依赖关系,您可以阅读描述该包的META文件,该文件可读性强,可以通过以下命令轻松找到

To figure out dependencies between those sublibraries, you can read the META file that describes the package, it is pretty readable and easy to locate with the following command

less $(ocamlfind query camlimages)/META

我建议使用camlimages.all,但是如果它抱怨您可以选择适合您的设置的子集.

I suggest using camlimages.all but if it complains you may select the subset that works for your setup.

这篇关于未绑定模块Png-Png.load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆