Reputation: 993
I'm trying to use ocamlfind with both the OCaml compiler and toplevel. From what I understood, I need to place the required libraries in the _tags file at the root of my project, so that the ocamlfind tool will take care of loading them - allowing me to open them in my modules like so :
open Sdl
open Sdlvideo
open Str
Currently, my _tags file looks like this :
<*>: pkg_sdl,pkg_str
I can apparently launch the ocamlfind command with the ocamlc or ocamlopt argument, provided I wan't to compile my project, but I did not see an option to launch the toplevel in the same manner. Is there any way to do this (something like "ocamlfind ocaml
")?
I also don't know how to place my project specific modules in the _tags file : imagine I have a module name Land. I am currently using the #use "land.ml"
directive to open the file and load the module, but it has been suggested that this is not good practice. What syntax should I use in _tags to specify it should be loaded by ocamlfind (considering land.ml is not in the ocamlfind search path) ?
Thank you, Charlie P.
Edit : According to the first answer of this post, the _tags file is not to be used with ocamlfind. The questions above still stand, there is just a new one to the list : what is the correct way to specify the libraries to ocamlfind ?
Upvotes: 4
Views: 4027
Reputation: 6697
One should distinguish ocamlfind packages, module names and file names. Source code references only module names. Modules are provided by .cma .cmo .cmx (and .cmi) files. Ocamlfind packages are named collections of such files (binaries built from some ocaml library sources). Ocamlfind is not strictly necessary to build a project - just specify the paths to all used libraries via -I. But if the project is distributed in source form - another people will have troubles building it cause used libraries are placed in different places. Then one seeks the way to specify the names of used "third party code pieces" and some external tool to resolve those names to actual paths. This tool is ocamlfind.
ocamlfind list
, most probably the package is named sdl
.ocamlfind ocamlc -package <package name> -linkpkg source.ml -o program
ocamlfind query <package name>
) and use this path with your build tool (plain Makefile, ocamlbuild, etc).Keep in mind that there is no one-to-one strict formal relationship between library name (purely human-targeted name e.g. ocaml-extlib
), module names (ExtLib
, Enum
, IO
, etc), file names (extLib.cma
) and ocamlfind package name (extlib
), though for convenience package maintainers and library authors usually choose guessable names :)
Upvotes: 4
Reputation: 12346
try this:
$ cat >> .ocamlinit
#use "topfind";;
#require "sdl";;
#require "sdlvideo";;
open Sdl
open Sdlvideo;;
open Str;;
.ocamlinit
is sourced from the current directory, falling back to /home/user/.ocamlinit
. you can explicitly override it via ocaml -init <filename>
Upvotes: 4
Reputation: 31
The _tags file is not for ocamlfind, but for ocamlbuild. Exemple : ocamlbuild land.native
Upvotes: 3