0

I've been trying to run a program that uses graphics (which I've already posted about here). This post and other posts have led me to the conclusion that I need create a ~/.bashrc and put in it:

alias ocaml="/usr/local/Cellar/ocaml/4.03.0/bin/ocaml”

However, /usr/local/Cellar/ocaml/4.03.0/bin/ocaml is not a valid file in my system. B/c when I ran this in the terminal:

$ cd /usr/local/Cellar/ocaml/4.03.0/bin
-bash: cd: /usr/local/Cellar/ocaml/4.03.0/bin: No such file or directory

But changing the version to 4.04.0 works:

$ cd /usr/local/Cellar/ocaml/4.04.0/bin

But when I ask the terminal what ocaml I'm running:

$ which ocaml
/Users/Username/.opam/4.03.0/bin/ocaml

It says I'm running 4.03.0

And my error message when I try to run an ocaml program using graphics is :

Error: Cannot find file /Users/Username/.opam/4.03.0/lib/ocaml/graphics.cma

So it seems like my terminal is running 4.03.0 but I don't have OCaml 4.03.0 in /usr/local/Cellar/ocaml/4.03.0/bin and instead I have 4.04.0??

That to me seems very strange.

If anyone could please help me out that would be greatly appreciated! I have spent hours trying to figure out how to run graphics on my computer and I have no clue why the solutions posted in previous StackOverflow posts are not helping :(

Community
  • 1
  • 1
14wml
  • 4,048
  • 11
  • 49
  • 97

2 Answers2

0

i don't find it strange. The alias command works only in your terminal, not for the entire system.

Probably you have "/Users/Username/.opam/4.03.0/bin/ocaml" in your PATH variable.

I suggest to do:

export PATH="/usr/local/Cellar/ocaml/4.04.0/bin:$PATH"

then:

which ocaml

and the path should be the 4.04 version

m47730
  • 2,061
  • 2
  • 24
  • 30
0

It looks like that you have multiple installations of OCaml on your machine. Some of them being installed via opam, and others either manually, or via system package management. I would suggest just to ignore the latter and focus on opam.

To use opam, you need to activate your switch. This can be done manually,

  eval `opam config env`

(Note the use of backticks)

You can also put it in your profile, so that opam will be activated every time you logged in. You can even ask opam to do it for you:

  opam config setup --user 

Finally, if you want to run a program, out of your normal terminal environment, and do not want to depend on some pre-setup steps (i.e., on a client's machine), then you can use opam config exec:

  opam config exec -- ocaml my-ocaml-script.ml
ivg
  • 34,431
  • 2
  • 35
  • 63
  • hmm but I want the version of Ocaml that has graphics. I reinstalled Ocaml using brew (`brew reinstall ocaml --with-x11`) and that's the one that should have graphics...how can I use that version of Ocaml? And how can I find out which version of Ocaml is the one with graphics.cma? – 14wml Dec 01 '16 at 15:22
  • First of all, you may install graphics on your opam installation, just do `opam install graphics`. Second, it looks like that your program was compiled with opam's 4.03 compiler, thats why it tries to look for a file. Third, it looks like that your setup is totally messed and I need to have a degree in telepathy in order to help you :) So, feel free to post your setup somewhere, so that we can help you. You're hitting the a/b problem, when it is already to late to try to solve problem b. Describe how do you compile your program, how do you run it, etc – ivg Dec 02 '16 at 00:30