diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml index ac719de3a5b..943061e65e6 100644 --- a/bindings/ocaml/Makefile.ocaml +++ b/bindings/ocaml/Makefile.ocaml @@ -65,6 +65,10 @@ OCAMLRPATH := $(RPATH) -Wl,'$$ORIGIN/../../lib' endif endif +# See http://caml.inria.fr/mantis/view.php?id=6642 +OCAMLORIGIN := -ccopt -L'$$CAMLORIGIN/..' \ + -ccopt $(RPATH) -ccopt -Wl,'$$CAMLORIGIN/..' + # Tools OCAMLCFLAGS += -I $(OcamlDir) $(addprefix -package ,$(FindlibPackages)) @@ -92,16 +96,18 @@ Compile.CMX := $(strip $(OCAMLFIND) opt -c $(OCAMLCFLAGS) $(OCAMLDEBUGFLAG) -o) ifdef OCAMLSTUBS # -dllib is engaged with ocamlc builds, $(OCAMLSTUBFLAGS) in ocamlc -custom builds. Archive.CMA := $(strip $(OCAMLFIND) c -a -dllib -l$(LIBRARYNAME) $(OCAMLSTUBFLAGS) \ - $(OCAMLDEBUGFLAG) -o) + $(OCAMLDEBUGFLAG) $(OCAMLORIGIN) -o) else Archive.CMA := $(strip $(OCAMLFIND) c -a -custom $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ - -o) + $(OCAMLORIGIN) -o) endif ifdef OCAMLSTUBS -Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLSTUBFLAGS) $(OCAMLDEBUGFLAG) -o) +Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLSTUBFLAGS) $(OCAMLDEBUGFLAG) \ + $(OCAMLORIGIN) -o) else -Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) -o) +Archive.CMXA := $(strip $(OCAMLFIND) opt -a $(OCAMLAFLAGS) $(OCAMLDEBUGFLAG) \ + $(OCAMLORIGIN) -o) endif # Source files diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake index 4473a7dcf17..c58ac9cb734 100644 --- a/cmake/modules/AddOCaml.cmake +++ b/cmake/modules/AddOCaml.cmake @@ -53,6 +53,8 @@ function(add_ocaml_library name) endif() set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}" + "-ccopt" "-L\\$CAMLORIGIN/.." + "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/.." ${ocaml_pkgs}) foreach( ocaml_dep ${ARG_OCAMLDEP} )