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

Initial switch creation fails on mac #3650

Closed
ospatil opened this issue Nov 2, 2018 · 11 comments
Closed

Initial switch creation fails on mac #3650

ospatil opened this issue Nov 2, 2018 · 11 comments

Comments

@ospatil
Copy link

ospatil commented Nov 2, 2018

# opam config report
# opam-version      2.0.1
# self-upgrade      no
# system            arch=x86_64 os=macos os-distribution=homebrew os-version=10.12.6
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
# read-state        OpamStd.OpamSys.Exit(50)

The error is as follows. I'm quite new to the Ocaml ecosystem, so please forgive me if I'm missing something really basic.

<><> Creating initial switch (ocaml-base-compiler) ><><><><><><><><><><><><>  🐫

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ocaml-base-compiler.4.07.1] downloaded from cache at https://opam.ocaml.org/cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
[ERROR] The compilation of ocaml-base-compiler failed at "/Users/op/.opam/opam-init/hooks/sandbox.sh build make
        world".

#=== ERROR while compiling ocaml-base-compiler.4.07.1 =========================#
# context     2.0.1 | macos/x86_64 |  | https://opam.ocaml.org#892303df
# path        ~/.opam/default/.opam-switch/build/ocaml-base-compiler.4.07.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build make world
# exit-code   2
# env-file    /var/folders/85/__swp0wn31lb_dpf00pgwxrn0n9b7k/T/opam-e1082265-40464/ocaml-base-compiler-40464-f0f09f.env
# output-file /var/folders/85/__swp0wn31lb_dpf00pgwxrn0n9b7k/T/opam-e1082265-40464/ocaml-base-compiler-40464-f0f09f.out
### output ###
# Undefined symbols for architecture x86_64:
# [...]
#       _caml_builtin_cprim in prims.o
#   "_caml_weak_get_copy", referenced from:
#       _caml_builtin_cprim in prims.o
#   "_caml_weak_set", referenced from:
#       _caml_builtin_cprim in prims.o
#   "_main", referenced from:
#      implicit entry/start for main executable
# ld: symbol(s) not found for architecture x86_64
# clang: error: linker command failed with exit code 1 (use -v to see invocation)
# make[1]: *** [ocamlrun] Error 1
# make: *** [coldstart] Error 2



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
┌─ The following actions failed
│ λ build ocaml-base-compiler 4.07.1
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray base
│ ∗ install base-threads  base
│ ∗ install base-unix     base
└─
# Run eval $(opam env) to update the current shell environment
Switch initialisation failed: clean up? ('n' will leave the switch partially installed) [Y/n] y
@ospatil
Copy link
Author

ospatil commented Nov 2, 2018

Please disregard. My mac had a mishmash of Gnu and clang tools due to something else I was working on. I cleaned it up and now the switch creation is successful.

@ospatil ospatil closed this as completed Nov 2, 2018
@anton-trunov
Copy link

Hi @ospatil! I'm experiencing this same issue after updating to Mojave (I use Homebrew). Could you share your solution, please?

@ospatil
Copy link
Author

ospatil commented Nov 7, 2018

@anton-trunov - I was tinkering with assembly and had gcc and Gnu binutils installed on my mac (still on Sierra) through Homebrew. It seems that this, especially the Gnu linker ld, spooked Opam and I was getting the error mentioned above. I uninstalled these, updated Xcode (along with it's command line tools) to latest and that solved the problem.
Hope this helps.

@anton-trunov
Copy link

@ospatil Thank you very much, it worked perfectly!

@irvinlim
Copy link

irvinlim commented Nov 8, 2018

To add on, if you installed GNU binutils via Homebrew:

brew unlink binutils

This might break existing setups so maybe relink it after you're done.

@mseri
Copy link
Member

mseri commented Nov 26, 2018

@irvinlim is this issue with binutils known on the homebrew side?

@irvinlim
Copy link

@mseri Not too sure, but it seems like the issue is either with the user or with opam, not the Homebrew binutils package. From what I see, the issue is that opam assumes that the linker is the default one on macOS, which could be justified.

Perhaps opam could support both the native linker and the binutils one.

I new to OCaml, so I know even less about opam; it's probably best to ask someone else.

@mseri
Copy link
Member

mseri commented Nov 26, 2018

I'll ping @rjbou and @AltGr just to make sure they are aware

@Leandros
Copy link

Leandros commented Dec 5, 2018

gnu binutils doesn't provide a linker (ld) on mac.
They only provide a couple of misc tools, like objdump, or readelf.
Attached is the full list of files which is provided by the binutils package in homebrew.

Edit: Looking at the error log, I suspect that the replaced ar or ranlib is the culprit.
The fix should be "simple", though. Both tools exist in /usr/bin, and should be preferred to the tools in /usr/local/bin.

/usr/local/bin/addr2line
/usr/local/bin/ar
/usr/local/bin/c++filt
/usr/local/bin/coffdump
/usr/local/bin/dlltool
/usr/local/bin/dllwrap
/usr/local/bin/elfedit
/usr/local/bin/gaddr2line
/usr/local/bin/gar
/usr/local/bin/gc++filt
/usr/local/bin/gcoffdump
/usr/local/bin/gdlltool
/usr/local/bin/gdllwrap
/usr/local/bin/gelfedit
/usr/local/bin/gnm
/usr/local/bin/gobjcopy
/usr/local/bin/gobjdump
/usr/local/bin/granlib
/usr/local/bin/greadelf
/usr/local/bin/gsize
/usr/local/bin/gsrconv
/usr/local/bin/gstrings
/usr/local/bin/gstrip
/usr/local/bin/gsysdump
/usr/local/bin/gwindmc
/usr/local/bin/gwindres
/usr/local/bin/nm
/usr/local/bin/objcopy
/usr/local/bin/objdump
/usr/local/bin/ranlib
/usr/local/bin/readelf
/usr/local/bin/size
/usr/local/bin/srconv
/usr/local/bin/strings
/usr/local/bin/strip
/usr/local/bin/sysdump
/usr/local/bin/windmc
/usr/local/bin/windres
/usr/local/include/ansidecl.h
/usr/local/include/bfd.h
/usr/local/include/bfdlink.h
/usr/local/include/diagnostics.h
/usr/local/include/dis-asm.h
/usr/local/include/plugin-api.h
/usr/local/include/symcat.h
[... omitted man pages ...]
/usr/local/lib/libbfd.a
/usr/local/lib/libopcodes.a

@bifeitang
Copy link

@Leandros Thanks for the explanation. I went into the same problem. My computer doesn't have gnu binutils installed, which indeed dose not contain linker binary (ld). But I don't really understand your solution. I'm on Mojave, which has ar and ranlib in both /usr/bin and /usr/local/bin. I wonder what is the "simple" solution you suggest to this problem?

@Leandros
Copy link

Leandros commented Jan 7, 2019

@bifeitang My solution was to unlink binutils using brew (brew unlink binutils). A temporary solution for your problem would be to rename the binaries in /use/local/bin for the build, and revert the rename once OCaml is build.

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

6 participants