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 init doesn't initialise a switch #5807

Open
InnesC-03 opened this issue Jan 26, 2024 · 22 comments
Open

opam init doesn't initialise a switch #5807

InnesC-03 opened this issue Jan 26, 2024 · 22 comments

Comments

@InnesC-03
Copy link

InnesC-03 commented Jan 26, 2024

When running opam init whilst following a tutorial to install OCaml, in the video it initialised a switch, however for me it just stops, and the terminal is ready for a new command.

(base) innescameron@Inness-MBP ~ % opam init

<><> Required setup - please read <><><><><><><><><><><><><><><><><><><><><>  🐫 

  In normal operation, opam only alters files within ~/.opam.

  However, to best integrate with your system, some environment variables
  should be set. If you allow it to, this initialisation step will update
  your zsh configuration by adding the following line to ~/.zshrc:

    [[ ! -r /Users/innescameron/.opam/opam-init/init.zsh ]] || source /Users/innescameron/.opam/opam-init/init.zsh  > /dev/null 2> /dev/null

  Otherwise, every time you want to access your opam installation, you will
  need to run:

    eval $(opam env)

  You can always re-run this setup with 'opam init' later.

Do you want opam to modify ~/.zshrc? [N/y/f]
(default is 'no', use 'f' to choose a different file) y
A hook can be added to opam's init scripts to ensure that the shell remains in
sync with the opam environment when they are loaded. Set that up? [y/N] y

User configuration:
  ~/.zshrc is already up-to-date.
@kit-ty-kate
Copy link
Member

kit-ty-kate commented Jan 26, 2024

this means that you already had setup opam in the past.

Maybe we could modify the In normal operation, opam only alters files within ~/.opam. line to be more explicit about that?

EDIT: also, please use the markdown codeblock when quoting a terminal output (using ```)

@InnesC-03
Copy link
Author

InnesC-03 commented Jan 26, 2024

but when I try and install any platform tools I get an error:

[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch

@kit-ty-kate
Copy link
Member

Have you tried to create a switch like the error message said? (you can open the manual for any command using opam <command> --help)

@InnesC-03
Copy link
Author

InnesC-03 commented Jan 26, 2024

Just tried and it failed, should I say y or n to the last bit?:


<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><>  🐫 
Switch invariant: ["ocaml" {= "5.1.1"}]
Constructing initial basis...
Number of 0-1 knapsack inequalities = 36
Constructing conflict graph...
Conflict graph has 12 + 10 = 22 vertices

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-options-vanilla.1
⬇ retrieved ocaml-base-compiler.5.1.1  (cached)
[ERROR] The compilation of ocaml-base-compiler.5.1.1 failed at "./configure --prefix=/Users/innescameron/.opam/default --docdir=/Users/innescameron/.opam/default/doc/ocaml -C CC=cc ASPP=cc -c".

#=== ERROR while compiling ocaml-base-compiler.5.1.1 ==========================#
# context     2.1.5 | macos/arm64 |  | https://opam.ocaml.org#e8c6d23b
# path        ~/.opam/default/.opam-switch/build/ocaml-base-compiler.5.1.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build ./configure --prefix=/Users/innescameron/.opam/default --docdir=/Users/innescameron/.opam/default/doc/ocaml -C CC=cc ASPP=cc -c
# exit-code   77
# env-file    ~/.opam/log/ocaml-base-compiler-17200-5e86d8.env
# output-file ~/.opam/log/ocaml-base-compiler-17200-5e86d8.out
### output ###
# [...]
# configure: creating cache config.cache
# configure: Configuring OCaml version 5.1.1
# checking build system type... x86_64-apple-darwin13.4.0
# checking host system type... x86_64-apple-darwin13.4.0
# checking target system type... x86_64-apple-darwin13.4.0
# checking for x86_64-apple-darwin13.4.0-ld... x86_64-apple-darwin13.4.0-ld
# checking how to print strings... printf
# checking for x86_64-apple-darwin13.4.0-gcc... cc
# checking whether the C compiler works... no
# configure: error: in `/Users/innescameron/.opam/default/.opam-switch/build/ocaml-base-compiler.5.1.1':
# configure: error: C compiler cannot create executables
# See `config.log' for more details



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
┌─ The following actions failed
│ λ build ocaml-base-compiler 5.1.1
└─ 
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray         base
│ ∗ install base-threads          base
│ ∗ install base-unix             base
│ ∗ install ocaml-options-vanilla 1
└─ 

<><> ocaml-base-compiler.5.1.1 troubleshooting ><><><><><><><><><><><><><><>  🐫 
=> A failure in the middle of the build may be caused by build parallelism
      (enabled by default).
      Please file a bug report at https://github.com/ocaml/opam-repository/issues
=> You can try installing again including --jobs=1
      to force a sequential build instead.
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [Y/n]

@kit-ty-kate
Copy link
Member

# checking whether the C compiler works... no

this might mean that you did not install xcode. Could you try again after xcode-select --install ?

If the same error happens, could you list up what you installed with Homebrew using brew list -1? It might be one of the typical issue with Homebrew (for example if you have installed binutils, brew unlink binutils should fix your issue)

@InnesC-03
Copy link
Author

I do already have Xcode installed, here's what was installed with homebrew:

(base) innescameron@Inness-MBP ~ % brew list -1
==> Formulae
gpatch

@kit-ty-kate
Copy link
Member

mmh, interesting. I don’t think i’ve seen that issue without any homebrew involvement yet.

Does the following couple of commands work?

cd /tmp
echo 'int main() {}' > test.c
cc test.c
./a.out

@InnesC-03
Copy link
Author

Tell me if I've done something wrong:

(base) innescameron@Inness-MBP ~ % cd /tmp
echo 'int main() {}' > test.c
cc test.c
./a.out
(base) innescameron@Inness-MBP /tmp % echo 'int main() {}' > test.c
(base) innescameron@Inness-MBP /tmp % cc test.c
(base) innescameron@Inness-MBP /tmp % ./a.out
(base) innescameron@Inness-MBP /tmp % 

@dbuenzli
Copy link
Contributor

Something looks wrong here:

# context     2.1.5 | macos/arm64

[...]

# checking build system type... x86_64-apple-darwin13.4.0

@kit-ty-kate
Copy link
Member

oh good catch! @InnesC-03 What does file "$(which opam)" give you?

@InnesC-03
Copy link
Author

(base) innescameron@Inness-MBP /tmp % file "$(which opam)"
/usr/local/bin/opam: Mach-O 64-bit executable arm64

@kit-ty-kate
Copy link
Member

mmh, I’m a bit lost, have you used Rosetta2 for anything in the past on this machine? Does cc --version say anything weird? What is in your PATH?

If none of these questions give us any hint to what’s going wrong, try:

opam switch create 5.1.1 # (and answer 'n' so the build directory is saved)
cd ~/.opam/5.1.1/.opam-switch/build/ocaml-base-compiler.5.1.1

and the config.log file should be verbose enough to help use find the culprit (you can attach it to a github comment after having redacted things that you don’t want to be public)

@InnesC-03
Copy link
Author

Ehm, I might've used Rosetta2 for things in the past.

here's what cc --version says:

(base) innescameron@Inness-MBP /tmp % cc --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 26, 2024

@InnesC-03 that looks alright you'll have to provide what @kit-ty-kate suggested, the output of env (redacted to your wish) and the config.log.

@InnesC-03
Copy link
Author

How do I find the config.log ?

@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 27, 2024

See @kit-ty-kate's message above.

@InnesC-03
Copy link
Author

I'm really sorry but I'm having a lot of trouble finding the config.log, here's the results of env don't think anything needs redacted:

(base) innescameron@Inness-MBP ocaml-base-compiler.5.1.1 % env
__CFBundleIdentifier=com.apple.Terminal
TMPDIR=/var/folders/66/hszk1fn9625dm1rml0g_pcn40000gn/T/
XPC_FLAGS=0x0
TERM=xterm-256color
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.5QzK0TQngr/Listeners
XPC_SERVICE_NAME=0
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=453
TERM_SESSION_ID=2A10BC9A-CD0D-410D-BBC2-2191166997CB
SHELL=/bin/zsh
HOME=/Users/innescameron
LOGNAME=innescameron
USER=innescameron
PATH=/Users/innescameron/.opam/5.1.1/bin:/Users/innescameron/opt/anaconda3/bin:/Users/innescameron/opt/anaconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
SHLVL=1
PWD=/Users/innescameron/.opam/5.1.1/.opam-switch/build/ocaml-base-compiler.5.1.1
OLDPWD=/tmp
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
MANPATH=/opt/homebrew/share/man::
INFOPATH=/opt/homebrew/share/info:
CONDA_EXE=/Users/innescameron/opt/anaconda3/bin/conda
_CE_M=
_CE_CONDA=
CONDA_PYTHON_EXE=/Users/innescameron/opt/anaconda3/bin/python
CONDA_SHLVL=1
CONDA_PREFIX=/Users/innescameron/opt/anaconda3
CONDA_DEFAULT_ENV=base
CONDA_PROMPT_MODIFIER=(base) 
CONDA_BACKUP_HOST=Inness-MBP
HOST=x86_64-apple-darwin13.4.0
CONDA_TOOLCHAIN_HOST=x86_64-apple-darwin13.4.0
CONDA_TOOLCHAIN_BUILD=x86_64-apple-darwin13.4.0
AR=x86_64-apple-darwin13.4.0-ar
AS=x86_64-apple-darwin13.4.0-as
CHECKSYMS=x86_64-apple-darwin13.4.0-checksyms
INSTALL_NAME_TOOL=x86_64-apple-darwin13.4.0-install_name_tool
LIBTOOL=x86_64-apple-darwin13.4.0-libtool
LIPO=x86_64-apple-darwin13.4.0-lipo
NM=x86_64-apple-darwin13.4.0-nm
NMEDIT=x86_64-apple-darwin13.4.0-nmedit
OTOOL=x86_64-apple-darwin13.4.0-otool
PAGESTUFF=x86_64-apple-darwin13.4.0-pagestuff
RANLIB=x86_64-apple-darwin13.4.0-ranlib
REDO_PREBINDING=x86_64-apple-darwin13.4.0-redo_prebinding
SEG_ADDR_TABLE=x86_64-apple-darwin13.4.0-seg_addr_table
SEG_HACK=x86_64-apple-darwin13.4.0-seg_hack
SEGEDIT=x86_64-apple-darwin13.4.0-segedit
SIZE=x86_64-apple-darwin13.4.0-size
STRINGS=x86_64-apple-darwin13.4.0-strings
STRIP=x86_64-apple-darwin13.4.0-strip
CLANG=x86_64-apple-darwin13.4.0-clang
LD=x86_64-apple-darwin13.4.0-ld
CC=x86_64-apple-darwin13.4.0-clang
OBJC=x86_64-apple-darwin13.4.0-clang
CC_FOR_BUILD=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang
OBJC_FOR_BUILD=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang
CPPFLAGS=-D_FORTIFY_SOURCE=2 -isystem /Users/innescameron/opt/anaconda3/include
CFLAGS=-march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/innescameron/opt/anaconda3/include
LDFLAGS=-Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/innescameron/opt/anaconda3/lib -L/Users/innescameron/opt/anaconda3/lib
LDFLAGS_LD=-pie -headerpad_max_install_names -dead_strip_dylibs -rpath /Users/innescameron/opt/anaconda3/lib -L/Users/innescameron/opt/anaconda3/lib
DEBUG_CFLAGS=-march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -Og -g -Wall -Wextra -isystem /Users/innescameron/opt/anaconda3/include
_CONDA_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_x86_64_apple_darwin13_4_0
CMAKE_PREFIX_PATH=:/Users/innescameron/opt/anaconda3
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CMAKE_ARGS=-DCMAKE_AR=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ar -DCMAKE_CXX_COMPILER_AR=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ar -DCMAKE_C_COMPILER_AR=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ar -DCMAKE_RANLIB=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ranlib -DCMAKE_CXX_COMPILER_RANLIB=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ranlib -DCMAKE_C_COMPILER_RANLIB=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ranlib -DCMAKE_LINKER=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-ld -DCMAKE_STRIP=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-strip -DCMAKE_INSTALL_NAME_TOOL=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-install_name_tool -DCMAKE_LIBTOOL=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-libtool -DCMAKE_OSX_DEPLOYMENT_TARGET= -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_SYSROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
MESON_ARGS=--buildtype release
ac_cv_func_malloc_0_nonnull=yes
ac_cv_func_realloc_0_nonnull=yes
host_alias=x86_64-apple-darwin13.4.0
build_alias=x86_64-apple-darwin13.4.0
BUILD=x86_64-apple-darwin13.4.0
CLANGXX=x86_64-apple-darwin13.4.0-clang++
CXX=x86_64-apple-darwin13.4.0-clang++
CXX_FOR_BUILD=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang++
CXXFLAGS=-march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -fmessage-length=0 -isystem /Users/innescameron/opt/anaconda3/include
DEBUG_CXXFLAGS=-march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -fmessage-length=0 -Og -g -Wall -Wextra -isystem /Users/innescameron/opt/anaconda3/include
CMDSTAN_OLD=
CMDSTAN=/Users/innescameron/opt/anaconda3/bin/cmdstan
OPAMNOENVNOTICE=true
OPAM_SWITCH_PREFIX=/Users/innescameron/.opam/5.1.1
LANG=en_GB.UTF-8
_=/usr/bin/env

@dbuenzli
Copy link
Contributor

No need to dig the log it's all there in the env.

Something is setting your CC, LD, OTOOL, RANLIB & co variables to x86_64-apple-darwin13.4.0-* binaries:

[...]
LD=x86_64-apple-darwin13.4.0-ld
CC=x86_64-apple-darwin13.4.0-clang
[...]

You need to get rid of all these things, ocaml's configure will pick them up.

@InnesC-03
Copy link
Author

So what is it I need to run? sorry this is all a bit over my head

@dbuenzli
Copy link
Contributor

dbuenzli commented Jan 27, 2024

I have no idea what setups these environment variables (though I suspect this conda thing is setting up these variables). Look at your .zshrc, .profile etc., get rid of the command(s) that setup these variables, create a new shell window and start over.

@kit-ty-kate
Copy link
Member

I concur with @dbuenzli, looking at the following line:

CXX_FOR_BUILD=/Users/innescameron/opt/anaconda3/bin/x86_64-apple-darwin13.4.0-clang++

it looks like the anaconda3 you installed is the x86_64 version instead of the arm64 and that, during its installation it also messed with your default environment variables and changed your default C compiler to point to the one installed by anaconda.

I'm not sure why they do that but it looks pretty scary to me

@kit-ty-kate
Copy link
Member

@InnesC-03 did it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants