0

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
shah
  • 3
  • 2
  • "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 Mar 21 '19 at 08:16
  • 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 Mar 21 '19 at 08:51
  • 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 Mar 21 '19 at 08:55
  • 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 Mar 21 '19 at 09:00
  • yea you are right... i did not know stackoverflow will add in that manner.. i am new to stackoverflow too... i forgot to give you the link of github project i am compiling.. https://github.com/ykazakov/cb-reasoner .. is there an alternative way to compile and run this project? i believe ocamlbuild is just an option... i could use other ways too..i guess – shah Mar 21 '19 at 09:02
  • The build process seems heavily dependent on ocamlbuild, so I wouldn't think so. Are you sure this is the only error or warning you get? Including the complete output in the question would be a good idea. – glennsl Mar 21 '19 at 09:25
  • 1
    i am able to compile under OCaml version 4.01.0. it seams there is some change in ocamlbuild thereafter hence the error – shah Mar 21 '19 at 13:04

1 Answers1

4

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.)

gasche
  • 31,259
  • 3
  • 78
  • 100
  • 1
    @shah Instead of saying "thank you" and "it works" you can accept the answer by clicking the checkmark beside it. That signals to others, both those looking _for_ an answer and those looking _to_ answer, that the question has a proper solution. – glennsl Mar 21 '19 at 21:33