0
votes

i am trying to compile a ocaml program (part of it shown below)

open Ocamlbuild_plugin
open Command

(** helper functions )
( splitting strings using a delimeter character *)
let rec strsplit sep str accu len =
try let idx = String.rindex_from str (len - 1) sep in
strsplit sep str ((String.sub str (idx + 1) (len - 1 - idx)) :: accu) idx
with Not_found -> (String.sub str 0 len) :: accu
let strsplit sep str = strsplit sep str [] (String.length str)

(** initializing variables from the environment *)
let host = Ocamlbuild_pack.Ocamlbuild_Myocamlbuild_config.system

the last line is causing unbound module error. What can i do? thanks

update 1:

The code is from a github project https://github.com/ykazakov/cb-reasoner

And i am following an instruction there to use "make" to compile the program .. this make file looks like this

BUILDDIR ?= _build
OCAMLBUILD ?= ocamlbuild
OCAMLBUILD := $(OCAMLBUILD) -build-dir $(BUILDDIR)

.PHONY: main clean clib

main:
    $(OCAMLBUILD) main/cb.native

all:
    $(OCAMLBUILD) main/cb.native jni cwrap/libcb.a

cwrap:  
    $(OCAMLBUILD) cwrap/libcb.a

jni:
    $(OCAMLBUILD) jni

clean: 
    $(OCAMLBUILD) -clean;\
    rm -f cb.native
1
"Unbound module" means the compiler doesn't know about the existence of this module. Are you telling it about it? How do you invoke the compiler? - glennsl
i used make to compile it BUILDDIR ?= _build OCAMLBUILD ?= ocamlbuild OCAMLBUILD := $(OCAMLBUILD) -build-dir $(BUILDDIR) .PHONY: main clean clib main: $(OCAMLBUILD) main/cb.native all: $(OCAMLBUILD) main/cb.native jni cwrap/libcb.a cwrap: $(OCAMLBUILD) cwrap/libcb.a jni: $(OCAMLBUILD) jni clean: $(OCAMLBUILD) -clean;\ rm -f cb.native - shah
i guess that module is coming from ocamlbuild related modules... (i already installed ocambuild using opam) since i am trying to compile a github project (link as above) i just followed the instruction to use make to compile. I am new to Ocaml .. if i missed anything do let me know - shah
I would think so, yes. I'm not intimately familiar with ocamlbuild, so I can't offer much help, just guidance in asking a good question. You should add the contents of your makefile to the question itself. It's not very readable in a comment. - glennsl
i am able to compile under OCaml version 4.01.0. it seams there is some change in ocamlbuild thereafter hence the error - shah

1 Answers

4
votes

I answered this question on the ocamlbuild issue tracker (I follow StackOverflow but less closely, sorry). Quoting below for convenience:

OCamlbuild exports a stable interface for plugin users as the Ocamlbuild_plugin module. Using Ocamlbuild_pack directly accesses ocamlbuild's internal definitions, and is recommended against as there are no guarantees of backward-compatibility.

In your specific case, a module is used by this code that indeed was removed in more recent ocamlbuild versions (its presence was an artifact of the specific way ocamlbuild's build system was integrated into the compiler distribution). I could correctly build this software with OCaml 3.12.1, 4.00.1 and 4.01.0, but not any more recent version of OCaml and ocamlbuild.

Using opam makes it easy to install old OCaml versions:

opam install 4.01.0
eval $(opam env --switch=4.01.0)
make # if in the project's directoyr

If you are interested in patching this software to make it compatible with more recent OCaml versions, we could discuss how to get the corresponding information in a more robust way.

In any case, I'm closing this as it is not a problem of ocamlbuild, but rather a maintenance question for cb-reasoner. (Of course, feel free to post further comments.)