OCaml-Wodi第2部分:使用安装的编译 [英] OCaml-Wodi Part 2: Compiling using what was installed

查看:327
本文介绍了OCaml-Wodi第2部分:使用安装的编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编译一个非常小的小插曲,看看lablgtk2是如何工作的。

 (* file:base.ml *)
let main()=
let window = GWindow .window()in
window#show();
GMain.Main.main()

let _ = main()


$ b b

我通过wodi32包管理器正确安装,并检查pgk-lib文件夹,以查看是否有gMain.cmx / cmi和gWindow.cmx / cmi文件(以及相应的.ml和.mli文件)。但是,当我运行以下compile命令:

 
$ ocamlc -I + lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml

我收到以下错误:

 
文件base.ml,第4行,字符15-29:
错误:未绑定的模块GWindow

为什么它找不到GMain和GWindow模块?有没有替代命令行编译指令我可以使用,将产生一个可执行文件(即Windows / Linux风格)?例如,是否有一种方法可以直接链接GMain和GWindow模块,以便编译器理解它们没有绑定?



很奇怪,当我运行以下命令,事情似乎工作,但只产生一个目标文件(即base.o,以及base.cmx,base.cmi):

 
$ ocamlfind opt -package lablgtk2 -linkpkg base.ml

如何将该对象转换为可执行文件?

$如果使用通过ocamlfind安装的库(几乎所有的库都提供了ocamlfind支持),总是使用ocamlfind作为ocaml(c | opt)的包装器。 。
只有ocamlfind可以解析这些库的'META'文件。和ocamlfind可以安装库到不同的位置(取决于你的findlib.conf和某些环境变量),简单的ocaml可能不会找到他们与'+ lib'-notation。



以下应适用:

  ocamlfind ocamlopt -package lablgtk2。 auto-init -linkpkg base.ml -o myprog.exe 
ocamlfind ocamlc -package lablgtk2.auto-init -linkpkg base.ml -o myprog_byte.exe

'。auto-init将为您添加gtkInit。


I am trying to compile a very small vignette to see how lablgtk2 works.

(* file: base.ml *)
let main () =
  let window = GWindow.window () in
  window#show ();
  GMain.Main.main ()

let _ = main ()

I have it properly installed via the wodi32 package manager and checked the pgk-lib folder to see that there are gMain.cmx/cmi and gWindow.cmx/cmi files (as well as the respective .ml and .mli files). However, when I run the following compile command:

$ ocamlc -I +lablgtk2 -o base lablgtk.cma gtkInit.cmo base.ml

I get the following error:

File "base.ml", line 4, characters 15-29:
Error: Unbound module GWindow

What's not correct? Why can it not find the GMain and GWindow modules? Is there an alternative command line compile directive I can use that will yield an executable (i.e. Windows/Linux style)? For example, is there a way to directly link the GMain and GWindow modules so the compiler understands that they're not unbound?

Weirdly enough, when I run the following command, things seem to work, but only yield an object file (i.e. base.o, as well as base.cmx, base.cmi):

$ ocamlfind opt -package lablgtk2 -linkpkg base.ml

How do I turn that object into an executable?

解决方案

Always use ocamlfind as a wrapper for ocaml(c|opt), if you use libraries installed via ocamlfind (nearly all libraries provide ocamlfind support nowadays). Only ocamlfind can parse the 'META'-files of these libraries. And ocamlfind can install libraries to different locations (depending on your findlib.conf and certain environmental varibles), plain ocaml possibly won't find them with the '+lib'-notation.

The following should work:

ocamlfind ocamlopt -package lablgtk2.auto-init -linkpkg base.ml -o myprog.exe
ocamlfind ocamlc -package lablgtk2.auto-init -linkpkg base.ml -o myprog_byte.exe

'.auto-init' will add gtkInit for you.

这篇关于OCaml-Wodi第2部分:使用安装的编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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