'opam install ocamlgraph' leads to 'ld: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC'

Please help.

issta16@issta16-VirtualBox:~/temp$ opam install ocamlgraph
The following actions will be performed:
  ∗ install dune         2.8.4 [required by ocamlgraph]
  ∗ install stdlib-shims 0.3.0 [required by ocamlgraph]
  ∗ install ocamlgraph   2.0.0
===== ∗ 3 =====
Do you want to continue? [Y/n] y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

[dune.2.8.4] found in cache
[ocamlgraph.2.0.0] found in cache
[stdlib-shims.0.3.0] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of dune failed at "/usr/local/bin/ocaml bootstrap.ml -j 1".

#=== ERROR while compiling dune.2.8.4 =========================================#
# context     2.0.8 | linux/x86_64 | ocaml-system.4.12.0 | https://opam.ocaml.org#4f507760
# path        ~/.opam/ocaml-system.4.12.0/.opam-switch/build/dune.2.8.4
# command     /usr/local/bin/ocaml bootstrap.ml -j 1
# exit-code   2
# env-file    ~/.opam/log/dune-19443-2dea01.env
# output-file ~/.opam/log/dune-19443-2dea01.out
### output ###
# [...]
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(unix.b.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(bigarray.b.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(memprof.b.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(domain.b.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(codefrag.b.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(interp.b.o): relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(misc.b.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: /usr/local/lib/ocaml/libcamlrun.a(fix_code.b.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
# /usr/bin/ld: final link failed: Nonrepresentable section on output
# collect2: error: ld returned 1 exit status
# File "boot/duneboot.ml", line 1:
# Error: Error while building custom runtime system



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build dune 2.8.4
└─ 
╶─ No changes have been performed

This error usually means that you upgraded your C compiler since you originally created your Opam switch. Short of reverting your compiler to an older version, I think the only solution is to completely rebuild your switch from scratch with that new compiler.

1 Like

@silene It turns out that the distribution was Ubuntu 16.04. The solution for my issues was to install Ubuntu 20.04 and then redo all the steps. Thanks for the help as well.