OCaml-Wodi Part 2: Compiling using what was installed

只愿长相守 提交于 2019-12-08 12:13:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16266275/ocaml-wodi-part-2-compiling-using-what-was-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!