Using "ocamlfind" to create the OCaml and toplevel find libraries (project specific)

I am trying to use ocamlfind with both the OCaml compiler and with full access. From what I understand, I need to put the necessary libraries in the _tags file at the root of my project so that the ocamlfind tool takes care of loading it, which allows me to open them in my modules as follows:

open Sdl open Sdlvideo open Str 

Currently, my _tags file looks like this:

 <*>: pkg_sdl,pkg_str 

I can apparently run the ocamlfind command with the ocamlc or ocamlopt argument if I don’t compile my project, but I did not see the ability to run toplevel in the same way. Is there a way to do this (something like " ocamlfind ocaml ")?

I also do not know how to place the project modules in the _tags file: imagine that I have the name of the module Earth . I am currently using the #use "land.ml" directive #use "land.ml" to open the file and load the module, but it has been suggested that this is not a good practice. What syntax should I use in _tags to specify it, ocamlfind should be loaded (given that land.ml is not in the ocamlfind search path)?

Thanks Charlie P.

Edit: according to the first response of this post, the _tags file should not be used with ocamlfind. The above questions are still there, there is only a new list: what is the right way to specify libraries for ocamlfind?

+4
source share
3 answers

try the following:

 $ cat >> .ocamlinit #use "topfind";; #require "sdl";; #require "sdlvideo";; open Sdl open Sdlvideo;; open Str;; 

.ocamlinit comes from the current directory, returning to /home/user/.ocamlinit . you can explicitly override it via ocaml -init <filename>

+4
source

Distinguish ocamlfind packages, module names, and file names. Source code refers only to module names. Modules are provided by .cma.cmo.cmx (and .cmi) files. Ocamlfind packages are called collections of such files (binaries created from some sources of the ocaml library). Ocamlfind is not strictly necessary to create a project - just specify the paths to all the libraries used through -I. But if the project is distributed in its original form, other people will have problems because the libraries used are located in different places. Then everyone looks for a way to specify the names of the "third-party code parts" used and some external tool for resolving these names to actual paths. This tool is ocamlfind.

  • First, find the ocamlfind package that provides the modules you need (in this case, Sdl and Sdlvideo - just run the ocamlfind list , most likely the package is called sdl .
  • Compile with ocamlfind ocamlc -package <package name> -linkpkg source.ml -o program
  • Alternatively, use ocamlfind to extract the path to the .cma file (and others) provided by the package ( ocamlfind query <package name> ) and use this path with the build tool (simple Makefile, ocamlbuild, etc.).
  • In addition, ocamlfind (designed for) takes away the burden of remembering how the actual .cma files are named, what compiler options are required, and in what order the packages depend on each other. You just need to specify the name of the package.

Keep in mind that there is no unambiguous formal relationship between the library name (purely human-targeted name, for example ocaml-extlib ), module names ( ExtLib , Enum , IO , etc.), file names ( extLib.cma ) and package name ocamlfind ( ExtLib ), although for supporting package packers and library authors usually choose valid names :)

+4
source

The _tags file is not for ocamlfind, but for ocamlbuild. Example: ocamlbuild land.native

+3
source

All Articles