FreeBSD: "opam install dune" fails

Dear All,

I am trying to setup ocaml on FreeBSD13.0-RELEASE-p4 and as a part of it was installing dune using ‘opam install dune’. However this command fails with the following error message. Kindly guide how to proceed with this. Regards
(ps: I have removed links ‘https://…’ to be able to make this post)

ankit@:~ $ opam install dune
The following actions will be performed:
  ∗ install ocamlfind                1.9.1    [required by ocamlfind-secondary]
  ∗ install ocaml-secondary-compiler 4.08.1-1 [required by ocamlfind-secondary]
  ∗ install ocamlfind-secondary      1.9.1    [required by dune]
  ∗ install dune                     2.9.1
===== ∗ 4 =====
Do you want to continue? [Y/n] y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ocaml-secondary-compiler.4.08.1-1] downloaded from...
[ocamlfind.1.9.1] downloaded from cache at ...
[dune.2.9.1] downloaded from cache at ...
[ocamlfind-secondary.1.9.1] downloaded from cache at ...

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of ocaml-secondary-compiler failed at
        "/usr/local/bin/gmake -j1 world.opt".
∗ installed ocamlfind.1.9.1

#=== ERROR while compiling ocaml-secondary-compiler.4.08.1-1 ==================#
# context     2.0.8 | freebsd/x86_64 | ocaml-system.4.05.0 | https://opam.ocaml.org#0eacced0
# path        /usr/home/ankit/.opam/default/.opam-switch/build/ocaml-secondary-compiler.4.08.1-1
# command     /usr/local/bin/gmake -j1 world.opt
# exit-code   2
# env-file    /usr/home/ankit/.opam/log/ocaml-secondary-compiler-4178-af57d6.env
# output-file /usr/home/ankit/.opam/log/ocaml-secondary-compiler-4178-af57d6.out
### output ###
# [...]
# cc -c -O2 -fno-strict-aliasing -fwrapv -Wall -g -fPIC -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  -DOCAML_STDLIB_DIR='"/usr/home/ankit/.opam/default/share/ocaml-secondary-compiler/lib"'  -o main_bpic.o main.c
# rm -f libcamlrun_pic.a && ar rc libcamlrun_pic.a  interp_bpic.o misc_bpic.o stacks_bpic.o fix_code_bpic.o startup_aux_bpic.o startup_byt_bpic.o freelist_bpic.o major_gc_bpic.o minor_gc_bpic.o memory_bpic.o alloc_bpic.o roots_byt_bpic.o globroots_bpic.o fail_byt_bpic.o signals_bpic.o signals_byt_bpic.o printexc_bpic.o backtrace_byt_bpic.o backtrace_bpic.o compare_bpic.o ints_bpic.o floats_bpic[...]
# cc -shared -o libcamlrun_shared.so interp_bpic.o misc_bpic.o stacks_bpic.o fix_code_bpic.o startup_aux_bpic.o startup_byt_bpic.o freelist_bpic.o major_gc_bpic.o minor_gc_bpic.o memory_bpic.o alloc_bpic.o roots_byt_bpic.o globroots_bpic.o fail_byt_bpic.o signals_bpic.o signals_byt_bpic.o printexc_bpic.o backtrace_byt_bpic.o backtrace_bpic.o compare_bpic.o ints_bpic.o floats_bpic.o str_bpic.o a[...]
# ld: error: duplicate symbol: caml_debug_info
# >>> defined at backtrace_byt.c:47
# >>>            backtrace_byt_bpic.o:(caml_debug_info)
# >>> defined at backtrace.c:31
# >>>            backtrace_bpic.o:(.bss+0x10)
# cc: error: linker command failed with exit code 1 (use -v to see invocation)
# gmake[1]: *** [Makefile:310: libcamlrun_shared.so] Error 1
# gmake[1]: Leaving directory '/usr/home/ankit/.opam/default/.opam-switch/build/ocaml-secondary-compiler.4.08.1-1/runtime'
# gmake: *** [Makefile:323: coldstart] Error 2



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-secondary-compiler 4.08.1-1
└─ 
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install ocamlfind 1.9.1
└─

This error seems to be one of the known error that appears when mixing recent version of gcc or clang with old version of OCaml. Normally, there are compatibility patches for the OCaml compiler in opam. Maybe you are missing an opam update and you see package versions without those patches?

Also, the simpler fix by far would be to upgrade your version of OCaml to a version that is at least as recent as your C compiler.

I opened an issue on opam-repository to track this: ocaml-secondary-compiler.4.08.1-1 fails to compile on FreeBSD · Issue #19763 · ocaml/opam-repository · GitHub

2 Likes

Thanks for the suggestions. I tried installing dune after running ‘opam update’ also. Same result. The version of ocaml is 4.05.0_1 and opam is 2.0.8_2 which are what are available in both FreeBSD ports and packages, so I am not sure how to update their versions.

You should be able to use the opam switch capability to install any current version of ocaml from opam list-available

I just tested in a fresh FreeBSD with

pkg install ocaml-opam 
opam init
opam switch install 4.13.1
... # eval the opam env depending on your shell
opam install dune

Hopefully that helps get you going.

Thanks a lot! This worked straightaway. I am relatively new to both FreeBSD and Ocaml, and now I can get started exploring further :slight_smile:

Edit: Following the instructions when I tried to install the ocaml-lsp-server, I am getting the following error-
(I have removed links for readability)

<><> Gathering sources ><><><><><><><><><><><><>
[csexp.1.5.1] downloaded from …
[cppo.1.6.8] downloaded from …
[dune-build-info.2.9.1] found in cache
[biniou.1.2.1] downloaded from …
[easy-format.1.3.2] downloaded from …
[ocamlfind.1.9.1] downloaded from …
[dot-merlin-reader.4.1] downloaded from …
[pp.1.1.2] downloaded from …
[ocamlformat-rpc-lib.0.19.0] downloaded from …
[ppx_yojson_conv_lib.v0.14.0] downloaded from …
[result.1.5] downloaded from …
[re.1.10.3] downloaded from …
[sexplib0.v0.14.0] downloaded from …
[yojson.1.7.0] downloaded from …

[ERROR] Could not synchronize
/usr/home/ankit/.opam/4.13.1/.opam-switch/sources/ocaml-lsp-server.1.9.0~4.13preview
from “git://github.com/kit-ty-kate/ocaml-lsp.git#413”:
“/usr/local/bin/git fetch -q” exited with code 128
[ERROR] The sources of the following couldn’t be obtained, aborting:
- ocaml-lsp-server.1.9.0~4.13preview

1 Like

git seems to be missing.

pkg install git

should fix that.

1 Like

Great, it worked! Once again thanks a lot.

It’d be good if the FreeBSD package depended on git (which most/all other distros do), but is that not very BSD-ish? (opam should also be clearer about the problem, and @kit-ty-kate’s opened an issue for that)

I took a quick look at the ocaml-opam port and the default pkg install does depend on git. I also verified on a fresh jail that it does install git by default.

Perhaps others are configuring something else, to ignore the pkg defaults?

1 Like

Hi, the first issue I had raised regarding dune installation was resolved by the following:

The latter issue I raised where kit-ty-kate suggested:

was due to some firewall restrictions at my end which I realised later. So, yes, git was not the issue here as things worked fine when I tried on another machine without firewall restrictions.

1 Like

Exactly - git and rsync are by default dependencies. You can deselect them with make config.

see FreeBSD: "opam install dune" fails - #11 by pmonson711 FreeBSD: "opam install dune" fails - #13 by hannes – by default, git and rsync are dependencies of ocaml-opam.