ocaml / opam-repository

Main public package repository for opam, the source package manager of OCaml.
https://opam.ocaml.org
Creative Commons Zero v1.0 Universal
517 stars 1.13k forks source link

Failed to install merlin and utop due to compilation error of ocamlfind and ocamlbuild #8690

Closed ghost closed 7 years ago

ghost commented 7 years ago

I tried to install the following packages on Archlinux. $ CHECK_IF_PREINSTALLED=false opam install merlin utop ocp-indent

This is the output.

The following actions will be performed:
  - install ocamlbuild  0.11.0                          [required by utop]
  - install ocamlfind   1.7.1                           [required by merlin, utop]
  - install topkg       0.8.1                           [required by cmdliner]
  - install react       1.2.0                           [required by utop]
  - install ppx_tools   5.0                             [required by lwt]
  - install ocp-build   1.99.18-beta                    [required by ocp-indent]
  - install easy-format 1.2.0                           [required by yojson]
  - install base-bytes  base                            [required by cppo, zed]
  - install cmdliner    1.0.0                           [required by ocp-indent]
  - install lwt         2.7.0                           [required by utop]
       For module Lwt_react, please install package lwt_react
  - install biniou      1.0.12                          [required by yojson]
  - install cppo        1.4.1                           [required by utop]
  - install ocp-indent  1.6.0
  - install yojson      1.3.3                           [required by merlin]
  - install camomile    0.8.5                           [required by zed]
  - install merlin      2.5.3
  - install zed         1.4                             [required by lambda-term]
  - install lambda-term 1.10.1                          [required by utop]
  - install utop        1.19.3
===== 19 to install =====
Do you want to continue ? [Y/n] y

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[biniou] Archive in cache
[camomile] Archive in cache
[cmdliner] Archive in cache
[cppo] Archive in cache
[easy-format] Archive in cache
[lambda-term] Archive in cache
[lwt] Archive in cache
[merlin] Archive in cache
[ocamlbuild] Archive in cache
[ocamlfind] Archive in cache
[ocp-build] Archive in cache
[ocp-indent] Archive in cache
[ppx_tools] Archive in cache
[react] Archive in cache
[topkg] Archive in cache
[utop] Archive in cache
[yojson] Archive in cache
[zed] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ERROR] The compilation of ocamlfind failed at "make opt".
[ERROR] The compilation of ocamlbuild failed at "make check-if-preinstalled all opam-install".

#=== ERROR while installing ocamlbuild.0.11.0 =================================#
# opam-version 1.2.2
# os           linux
# command      make check-if-preinstalled all opam-install
# path         /home/ikh/.opam/system/build/ocamlbuild.0.11.0
# compiler     system (4.04.0)
# exit-code    2
# env-file     /home/ikh/.opam/system/build/ocamlbuild.0.11.0/ocamlbuild-27721-48c407.env
# stdout-file  /home/ikh/.opam/system/build/ocamlbuild.0.11.0/ocamlbuild-27721-48c407.out
# stderr-file  /home/ikh/.opam/system/build/ocamlbuild.0.11.0/ocamlbuild-27721-48c407.err
### stdout ###
# [...]
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -c src/main.ml
# mkdir -p tmp
# ocamlopt.opt -pack src/const.cmx src/loc.cmx src/discard_printf.cmx src/signatures.cmi src/my_std.cmx src/my_unix.cmx src/tags.cmx src/display.cmx src/log.cmx src/shell.cmx src/bool.cmx src/glob_ast.cmx src/glob_lexer.cmx src/glob.cmx src/lexers.cmx src/param_tags.cmx src/command.cmx src/ocamlbuild_config.cmx src/ocamlbuild_where.cmx src/slurp.cmx src/options.cmx src/pathname.cmx src/configuration.cmx src/flags.cmx src/hygiene.cmx src/digest_cache.cmx src/resource.cmx src/rule.cmx src/solver.cmx src/report.cmx src/tools.cmx src/fda.cmx src/findlib.cmx src/ocaml_arch.cmx src/ocaml_utils.cmx src/ocaml_dependencies.cmx src/ocaml_compiler.cmx src/ocaml_tools.cmx src/ocaml_specific.cmx src/exit_codes.cmx src/plugin.cmx src/hooks.cmx src/main.cmx -o tmp/ocamlbuild_pack.cmx
# mv tmp/ocamlbuild_pack.cmx src/ocamlbuild_pack.cmx
# mv tmp/ocamlbuild_pack.o src/ocamlbuild_pack.o
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -c src/ocamlbuild_plugin.ml
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -c src/ocamlbuild_executor.ml
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -c src/ocamlbuild_unix_plugin.ml
# ocamlopt.opt -for-pack Ocamlbuild_pack -w L -w R -w Z -I src -I +unix -safe-string -bin-annot -c src/ocamlbuild.ml
# ocamlopt.opt -I +unix -I src -o ocamlbuild.native unix.cmxa src/ocamlbuild_pack.cmx src/ocamlbuild_plugin.cmx src/ocamlbuild_executor.cmx src/ocamlbuild_unix_plugin.cmx src/ocamlbuild.cmx
### stderr ###
# [...]
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(finalise.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(custom.o): relocation R_X86_64_32 against symbol `caml_custom_table' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(unix.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(backtrace.o): relocation R_X86_64_32 against symbol `caml_backtrace_last_exn' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(startup.o): relocation R_X86_64_32S against symbol `caml_data_segments' can not be used whenmaking a shared object; recompile with -fPIC
# /usr/bin/ld: final link failed: Nonrepresentable section on output
# collect2: error: ld returned 1 exit status
# File "caml_startup", line 1:
# Error: Error during linking
# make: *** [Makefile:131: ocamlbuild.native] Error 2

#=== ERROR while installing ocamlfind.1.7.1 ===================================#
# opam-version 1.2.2
# os           linux
# command      make opt
# path         /home/ikh/.opam/system/build/ocamlfind.1.7.1
# compiler     system (4.04.0)
# exit-code    2
# env-file     /home/ikh/.opam/system/build/ocamlfind.1.7.1/ocamlfind-27721-f0f09f.env
# stdout-file  /home/ikh/.opam/system/build/ocamlfind.1.7.1/ocamlfind-27721-f0f09f.out
# stderr-file  /home/ikh/.opam/system/build/ocamlfind.1.7.1/ocamlfind-27721-f0f09f.err
### stdout ###
# [...]
# ocamlopt -I +compiler-libs -opaque -c fl_lint.ml
# ocamlopt -I +compiler-libs -a -o findlib.cmxa findlib_config.cmx fl_split.cmx fl_metatoken.cmx fl_meta.cmx fl_metascanner.cmx fl_topo.cmx fl_package_base.cmx findlib.cmx fl_args.cmx fl_lint.cmx
# if [ 1 -gt 0 ]; then \
#     ocamlopt -I +compiler-libs -shared -o findlib.cmxs findlib_config.cmx fl_split.cmx fl_metatoken.cmx fl_meta.cmx fl_metascanner.cmx fl_topo.cmx fl_package_base.cmx findlib.cmx fl_args.cmx fl_lint.cmx; \
# fi
# ocamlopt -I +compiler-libs -opaque -c ocaml_args.ml
# ocamlopt -I +compiler-libs -opaque -c frontend.ml
# ocamlopt -I +compiler-libs -o ocamlfind_opt findlib.cmxa unix.cmxa \
#          ocaml_args.cmx frontend.cmx
# make[1]: Leaving directory '/home/ikh/.opam/system/build/ocamlfind.1.7.1/src/findlib'
### stderr ###
# [...]
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(custom.o): relocation R_X86_64_32 against symbol `caml_custom_table' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(unix.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(backtrace.o): relocation R_X86_64_32 against symbol `caml_backtrace_last_exn' can not be used when making a shared object; recompile with -fPIC
# /usr/bin/ld: /usr/lib/ocaml/libasmrun.a(startup.o): relocation R_X86_64_32S against symbol `caml_data_segments' can not be used whenmaking a shared object; recompile with -fPIC
# /usr/bin/ld: final link failed: Nonrepresentable section on output
# collect2: error: ld returned 1 exit status
# File "caml_startup", line 1:
# Error: Error during linking
# make[1]: *** [Makefile:52: ocamlfind_opt] Error 2
# make: *** [Makefile:17: opt] Error 2

=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The following actions were aborted
  - install base-bytes  base
  - install biniou      1.0.12
  - install camomile    0.8.5
  - install cmdliner    1.0.0
  - install cppo        1.4.1
  - install easy-format 1.2.0
  - install lambda-term 1.10.1
  - install lwt         2.7.0
  - install merlin      2.5.3
  - install ocp-build   1.99.18-beta
  - install ocp-indent  1.6.0
  - install ppx_tools   5.0
  - install react       1.2.0
  - install topkg       0.8.1
  - install utop        1.19.3
  - install yojson      1.3.3
  - install zed         1.4
The following actions failed
  - install ocamlbuild 0.11.0
  - install ocamlfind  1.7.1
No changes have been performed

The error messages suggest recompiling with -fPIC. It might be similar to this issue of the Haskell build tool stack which also needs recomiling with -fPIC. This issue has been fixed in ghc 8.0.2 release which gets installed when I run stack setup. https://github.com/commercialhaskell/stack/issues/2712

So the question is how should I fix this issue in opam? I am new to the ocaml ecosystem.

nojb commented 7 years ago

Which version of ocaml are you using and how was it installed ?

nojb commented 7 years ago

OK, I see it is 4.04.0, but how was it installed ?

let-def commented 7 years ago

Since the error messages refer to /usr/lib/ocaml/, I assume it is a system switch. My experience with system switches is that they are generally unreliable (the system package manager can bump versions without telling opam, especially on arch were updates are frequent).

I would suggest using a local switch, opam switch 4.04.0 (build and compile locally).

gasche commented 7 years ago

Could it be a problem with the ocaml package on Archlinux that should be compiled with -fPIC but isn't? In any case, this looks like an environment misconfiguration rather than an upstream bug.

ghost commented 7 years ago

Thanks guys for taking the time to help out with this issue. I have worked around the issue as per @let-def 's suggestion by using opam switch 4.04.0. I was able to install those packages without any problem on a different machine with the same version of ocaml though.