Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opam env does not set OCAMLPATH #27495

Open
Frigory33 opened this issue Feb 17, 2025 · 4 comments
Open

opam env does not set OCAMLPATH #27495

Frigory33 opened this issue Feb 17, 2025 · 4 comments

Comments

@Frigory33
Copy link
Contributor

My system is Manjaro. A lot of packages fail to install in switches other than the default one, for instance menhir or js_of_ocaml-ocamlbuild, with errors such as:

#=== ERROR while compiling js_of_ocaml-ocamlbuild.5.0 =========================#
# context     2.3.0 | linux/x86_64 | ocaml-base-compiler.5.2.1 | https://opam.ocaml.org#d87296a7b656d47b7042e7e608a5fa863b3a51f9
# path        ~/.opam/ocaml-base-compiler.5.2.1/.opam-switch/build/js_of_ocaml-ocamlbuild.5.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p js_of_ocaml-ocamlbuild -j 3 --promote-install-files=false @install
# exit-code   1
# env-file    ~/.opam/log/js_of_ocaml-ocamlbuild-38916-d17c67.env
# output-file ~/.opam/log/js_of_ocaml-ocamlbuild-38916-d17c67.out
### output ###
# (cd _build/default && /home/frigory/.opam/ocaml-base-compiler.5.2.1/bin/ocamlc.opt -w -40 -g -bin-annot -bin-annot-occurrences -I .ocamlbuild_js_of_ocaml.objs/byte -I /home/frigory/.opam/default/lib/ocamlbuild -I /home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml/str -I /home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml/unix -no-alias-deps -o .ocamlbuild_js_of_ocaml.objs/byte/ocamlb[...]
# File "ocamlbuild_js_of_ocaml.mli", line 1:
# Error: "/home/frigory/.opam/default/lib/ocamlbuild/ocamlbuild_plugin.cmi"
#        is not a compiled interface for this version of OCaml.
# It seems to be for a newer version of OCaml.

As you can see, it looks like some files are looked for in the default opam switch. There is -I /home/frigory/.opam/default/lib/ocamlbuild in the compilation command. With menhir, I have -I /home/frigory/.opam/default/lib/menhirLib -I /home/frigory/.opam/default/lib/menhirSdk.

Where does this problem come from? I don’t get those errors on Windows: my opam switches work on Windows. But I’m getting this error on my 2 Manjaro systems (which are not in sync).

@kit-ty-kate
Copy link
Member

Somehow there seems to be a mixup between the environment of your default switch and your current switch (named ocaml-base-compiler.5.2.1).

Could you show the output of the env, opam env, ocamlc -config and which -a ocamlopt commands?

@Frigory33
Copy link
Contributor Author

$ env
SHELL=/bin/bash
SESSION_MANAGER=local/Chambsyl-Manjaro:@/tmp/.ICE-unix/1244,unix/Chambsyl-Manjaro:/tmp/.ICE-unix/1244
CAML_LD_LIBRARY_PATH=/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/stublibs:/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml/stublibs:/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml
WINDOWID=50331655
OCAML_TOPLEVEL_PATH=/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/toplevel
COLORTERM=truecolor
OCAMLPATH=/home/frigory/.opam/default/lib
XDG_CONFIG_DIRS=/etc/xdg
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
NVM_INC=/home/frigory/.nvm/versions/node/v16.20.2/include/node
HISTCONTROL=ignoredups
XDG_MENU_PREFIX=xfce-
LC_ADDRESS=fr_FR.UTF-8
LC_NAME=fr_FR.UTF-8
SSH_AUTH_SOCK=/tmp/ssh-XXXXXXWnSCOa/agent.1324
GRADLE_HOME=/usr/share/java/gradle
XDG_CONFIG_HOME=/home/frigory/.config
DESKTOP_SESSION=xfce
LC_MONETARY=fr_FR.UTF-8
SSH_AGENT_PID=1325
EDITOR=vim
GTK_MODULES=canberra-gtk-module:canberra-gtk-module
XDG_SEAT=seat0
OCAMLTOP_INCLUDE_PATH=
PWD=/home/frigory
LOGNAME=frigory
XDG_SESSION_DESKTOP=xfce
QT_QPA_PLATFORMTHEME=qt5ct
XDG_SESSION_TYPE=x11
MANPATH=/home/frigory/.nvm/versions/node/v16.20.2/share/man::/home/frigory/.opam/ocaml-base-compiler.5.2.1/man
XAUTHORITY=/home/frigory/.Xauthority
OPAM_SWITCH_PREFIX=/home/frigory/.opam/ocaml-base-compiler.5.2.1
XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/frigory
MOTD_SHOWN=pam
GDM_LANG=fr_FR.utf8
GTK2_RC_FILES=/home/frigory/.gtkrc-2.0
HOME=/home/frigory
LC_PAPER=fr_FR.UTF-8
LANG=fr_FR.utf8
XDG_CURRENT_DESKTOP=XFCE
VTE_VERSION=7803
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_CACHE_HOME=/home/frigory/.cache
NVM_DIR=/home/frigory/.nvm
XDG_SESSION_CLASS=user
LC_IDENTIFICATION=fr_FR.UTF-8
TERM=xterm-256color
USER=frigory
DISPLAY=:0.0
SHLVL=1
NVM_CD_FLAGS=
LC_TELEPHONE=fr_FR.UTF-8
LC_MEASUREMENT=fr_FR.UTF-8
XDG_VTNR=7
XDG_SESSION_ID=2
LD_LIBRARY_PATH=/home/frigory/.local/lib:/usr/local/lib
XDG_RUNTIME_DIR=/run/user/1000
DEBUGINFOD_URLS=https://debuginfod.archlinux.org 
LC_TIME=fr_FR.UTF-8
XDG_DATA_DIRS=/home/frigory/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/usr/share
PATH=/home/frigory/.opam/ocaml-base-compiler.5.2.1/bin:/home/frigory/.nvm/versions/node/v16.20.2/bin:/home/frigory/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/opt/android-sdk/platform-tools:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin
GDMSESSION=xfce
SAL_USE_VCLPLUGIN=gtk
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
NVM_BIN=/home/frigory/.nvm/versions/node/v16.20.2/bin
MAIL=/var/spool/mail/frigory
LC_NUMERIC=fr_FR.UTF-8
OPAM_LAST_ENV=/home/frigory/.opam/.last-env/env-35f680a1cecbd39bc8b85bd8416bf196-0
_=/usr/bin/env
$ opam env
OPAM_LAST_ENV='/home/frigory/.opam/.last-env/env-35f680a1cecbd39bc8b85bd8416bf196-0'; export OPAM_LAST_ENV;
OPAM_SWITCH_PREFIX='/home/frigory/.opam/ocaml-base-compiler.5.2.1'; export OPAM_SWITCH_PREFIX;
CAML_LD_LIBRARY_PATH='/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/stublibs:/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml/stublibs:/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml'; export CAML_LD_LIBRARY_PATH;
OCAML_TOPLEVEL_PATH='/home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/toplevel'; export OCAML_TOPLEVEL_PATH;
MANPATH='/home/frigory/.nvm/versions/node/v16.20.2/share/man::/home/frigory/.opam/ocaml-base-compiler.5.2.1/man'; export MANPATH;
PATH='/home/frigory/.opam/ocaml-base-compiler.5.2.1/bin:/home/frigory/.nvm/versions/node/v16.20.2/bin:/home/frigory/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/opt/android-sdk/platform-tools:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin'; export PATH;
$ ocamlc -config
version: 5.2.1
standard_library_default: /home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml
standard_library: /home/frigory/.opam/ocaml-base-compiler.5.2.1/lib/ocaml
ccomp_type: cc
c_compiler: gcc
ocamlc_cflags:  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread
ocamlc_cppflags:  -D_FILE_OFFSET_BITS=64 
ocamlopt_cflags:  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread
ocamlopt_cppflags:  -D_FILE_OFFSET_BITS=64 
bytecomp_c_compiler: gcc  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread  -D_FILE_OFFSET_BITS=64 
native_c_compiler: gcc  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread  -D_FILE_OFFSET_BITS=64 
bytecomp_c_libraries: -lzstd  -lm  -lpthread
native_c_libraries:  -lm  -lpthread
native_ldflags: 
native_pack_linker: ld -r -o 
native_compiler: true
architecture: amd64
model: default
int_size: 63
word_size: 64
system: linux
asm: as
asm_cfi_supported: true
with_frame_pointers: false
ext_exe: 
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
host: x86_64-pc-linux-gnu
target: x86_64-pc-linux-gnu
flambda: false
safe_string: true
default_safe_string: true
flat_float_array: true
function_sections: true
afl_instrument: false
tsan: false
windows_unicode: false
supports_shared_libraries: true
native_dynlink: true
naked_pointers: false
exec_magic_number: Caml1999X034
cmi_magic_number: Caml1999I034
cmo_magic_number: Caml1999O034
cma_magic_number: Caml1999A034
cmx_magic_number: Caml1999Y034
cmxa_magic_number: Caml1999Z034
ast_impl_magic_number: Caml1999M034
ast_intf_magic_number: Caml1999N034
cmxs_magic_number: Caml1999D034
cmt_magic_number: Caml1999T034
linear_magic_number: Caml1999L034
$ which -a ocamlopt
/home/frigory/.opam/ocaml-base-compiler.5.2.1/bin/ocamlopt
/usr/bin/ocamlopt
/bin/ocamlopt

@Frigory33
Copy link
Contributor Author

Indeed, the culprit is OCAMLPATH which is set in my .bashrc… I didn’t notice it! And I don’t remember why I set this variable. If I set it to the right value, things work.

Why isn’t this variable set by opam env?

@Frigory33 Frigory33 changed the title Installation of packages fails because it looks for files in the default switch opam env does not set OCAMLPATH Feb 19, 2025
@Frigory33
Copy link
Contributor Author

OK, so this is about setting automatically OCAMLPATH by opam env to avoid such messes. Do you think it would be a good idea?

@kit-ty-kate kit-ty-kate transferred this issue from ocaml/opam Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants