Hello friends,
I’m trying to use Dune with camlpdf
and I’m running into trouble getting a project-aware repl. dune build
works just fine, but then I get screwy linking error when I try to run dune utop
:
> opam exec -- dune utop
File "_build/default", line 1, characters 0-0:
/usr/bin/ld: cannot find -lcamlpdf_stubs: No such file or directory
/usr/bin/ld: cannot find -lxdg_stubs: No such file or directory
/usr/bin/ld: cannot find -llambda_term_stubs: No such file or directory
/usr/bin/ld: cannot find -llwt_unix_stubs: No such file or directory
collect2: error: ld returned 1 exit status
File "_none_", line 1:
Error: Error while building custom runtime system
Manually loading packages with findlib
in the REPL the old-fashioned way works:
> rlwrap ocaml
OCaml version 4.14.2
Enter #help;; for help.
# #use "topfind";;
# ****************
# - : unit = ()
Findlib has been successfully loaded. Additional directives:
#require "package";; to load a package
#list;; to list the available packages
#camlp4o;; to load camlp4 (standard syntax)
#camlp4r;; to load camlp4 (revised syntax)
#predicates "p,q,...";; to set these predicates
Topfind.reset();; to force that packages will be reloaded
#thread;; to enable threads
- : unit = ()
# #require "camlpdf";;
# ********************
# /home/teichman/.opam/ocaml-basics/lib/camlpdf: added to search path
/home/teichman/.opam/ocaml-basics/lib/camlpdf/camlpdf.cma: loaded
# #show Pdf;;
...etc...
I tried getting dune
to tell me the compiler command it ran:
> opam exec -- dune utop --verbose
Shared cache: enabled-except-user-rules
Shared cache location: /home/teichman/.cache/dune/db
Workspace root: /home/teichman/tmp/aaargh-ld-problem
Auto-detected concurrency: 28
Dune context:
{ name = "default"
; kind = "default"
; profile = Dev
; merlin = true
; fdo_target_exe = None
; build_dir = In_build_dir "default"
; instrument_with = []
}
Running[1]: (cd _build/default && /home/teichman/.opam/ocaml-basics/bin/ocamlc.opt -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats -short-paths -keep-locs -w -24 -g -o .utop/utop.bc /home/teichman/.opam/ocaml-basics/lib/ocaml/compiler-libs/ocamlcommon.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/compiler-libs/ocamlbytecomp.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/compiler-libs/ocamltoplevel.cma /home/teichman/.opam/ocaml-basics/lib/findlib/findlib.cma /home/teichman/.opam/ocaml-basics/lib/findlib/findlib_top.cma /home/teichman/.opam/ocaml-basics/lib/logs/logs.cma /home/teichman/.opam/ocaml-basics/lib/lwt/lwt.cma /home/teichman/.opam/ocaml-basics/lib/logs/lwt/logs_lwt.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/unix.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/bigarray.cma /home/teichman/.opam/ocaml-basics/lib/ocplib-endian/ocplib_endian.cma /home/teichman/.opam/ocaml-basics/lib/ocplib-endian/bigstring/ocplib_endian_bigstring.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/threads/threads.cma /home/teichman/.opam/ocaml-basics/lib/lwt/unix/lwt_unix.cma -I /home/teichman/.opam/ocaml-basics/lib/lwt/../stublibs /home/teichman/.opam/ocaml-basics/lib/react/react.cma /home/teichman/.opam/ocaml-basics/lib/lwt_react/lwt_react.cma /home/teichman/.opam/ocaml-basics/lib/result/result.cma /home/teichman/.opam/ocaml-basics/lib/uutf/uutf.cma /home/teichman/.opam/ocaml-basics/lib/uucp/uucp.cma /home/teichman/.opam/ocaml-basics/lib/uuseg/uuseg.cma /home/teichman/.opam/ocaml-basics/lib/zed/zed.cma /home/teichman/.opam/ocaml-basics/lib/trie/trie.cma /home/teichman/.opam/ocaml-basics/lib/mew/mew.cma /home/teichman/.opam/ocaml-basics/lib/mew_vi/mew_vi.cma /home/teichman/.opam/ocaml-basics/lib/lambda-term/lambda_term.cma -I /home/teichman/.opam/ocaml-basics/lib/lambda-term/../stublibs /home/teichman/.opam/ocaml-basics/lib/xdg/xdg.cma -I /home/teichman/.opam/ocaml-basics/lib/xdg/../stublibs /home/teichman/.opam/ocaml-basics/lib/utop/uTop.cma /home/teichman/.opam/ocaml-basics/lib/camlp-streams/camlp_streams.cma /home/teichman/.opam/ocaml-basics/lib/ocaml/str.cma /home/teichman/.opam/ocaml-basics/lib/prelude/prelude.cma /home/teichman/.opam/ocaml-basics/lib/etude/etude.cma /home/teichman/.opam/ocaml-basics/lib/camlpdf/camlpdf.cma lib/lib.cma .utop/.utop.eobjs/byte/dune__exe__Utop.cmo -linkall -warn-error -31)
File "_build/default", line 1, characters 0-0:
Command [1] exited with code 2:
The errors that command throws when I run it are the same as the errors I get running dune utop
. And I found that when I added -a
with an absolute path to libcamlpdf_stubs.a
to the (cd _build/default &&
etc. command and ran the command directly in my shell, it succeded! So theoretically, if I could get Dune to do the same thing, dune utop
would work?
I created a dummy project on GitHub to demonstrate the problem, in case anyone wants to try reproducing it:
Anyway, I’d really like to be able to use dune utop
the way I would in one of my normal OCaml projects. Does anyone know of a way I can get dune utop
to run the right command to link with libcamlpdf_stubs.a
etc. without blowing up? It would be a drag to have to change my normal build-a-custom-toplevel-with-dune workflow for this project.
Thanks as always!
-Matt