0

Following this post I installed brew and then reinstalled ocaml to include graphics:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew cask install xquartz
brew reinstall ocaml --with-x11

But after restarting my computer, when I tried to run an ocaml program that used graphics I got the error

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

The post also said:

Finally remember to check that the instance of ocaml that is running is the one in /usr/local/Cellar/objective-caml/x.yy.z[_w]/bin, and if it isn't then prepend that url to your PATH environment variable.

How do I do check the instance of ocaml that is running? And what does the poster mean by "prepending that url to your PATH environment"?

I've tried changing my directory to that path, but I get an error:

$ cd /usr/local/Cellar/objective-caml/
-bash: cd: /usr/local/Cellar/objective-caml/: No such file or directory

If someone could please tell me what I need to do to get graphics.cma working that would be great!


UPDATES:

I've tried creating .bashrc and putting in

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

Yet with no avail...I'm quite lost on what to do. If anyone could give me an inkling of what to do that would be great!

(Note: I put 4.04.0 instead of 4.03.0because when I explored the directory /usr/local/Cellar/ocaml/4.03.0/bin/ocaml but the directory /usr/local/Cellar/ocaml/4.04.0/bin/ocaml does)

Community
  • 1
  • 1
14wml
  • 4,048
  • 11
  • 49
  • 97
  • none of the documented fixes worked for me installing ocaml 4.06.0 on Mac OS Sierra 10.12.6. I left a comment on [this question](https://stackoverflow.com/questions/18435927/ocaml-unbound-graphics-module) explaining what worked for me. – Jim Reesman Dec 09 '17 at 12:21

2 Answers2

2

How do I do check the instance of ocaml that is running?

If your question is: what program is running when you type ocaml in a terminal window at the shell prompt (or more generally thru execvp and other functions)? then you should use the which ocaml command.

And what does the poster mean by "prepending that url to your PATH environment"?

Read more about the PATH variable. It is often set in your ~/.bashrc file (which you should probably and carefully edit once using your favorite editor) -or some other bash initialization file- if your interactive shell is bash. You should check what it is with the echo $PATH command. See also this. Notice that ~/.bashrc is expanded by your shell during globbing. Read also the documentation of bash notably the Bash Startup Files chapter.

If you are using opam you should read its documentation. Notably this question (mentioning PATH) from its FAQ.

Since aliases are mostly for interactive shells, defining an alias is not enough for most shell scripts. You really need to change your $PATH and/or add files (or symlinks) in directories mentioned in it.

PS. Understanding the role of PATH and how to set it is mandatory for serious use of the command line, notably on POSIX systems.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • You probably need to edit your `~/.bashrc` file, but you also need to understand the content of that file before editing it. How exactly is your particular account set we cannot tell. – Basile Starynkevitch Dec 01 '16 at 06:02
  • You don't need to locate it. It is in `~/.bashrc` that your shell expands like `$HOME/.bashrc`; so if your home directory is `/home/ongm` you need to edit `/home/ongm/.bashrc` with some editor (like `emacs` or `vim` or whatever editor you use). Perhaps running `open ~/.bashrc` might be enough to start an editor, but this is system specific. – Basile Starynkevitch Dec 01 '16 at 06:07
  • okay i did `$ cd ~` then `$ ls -a` like this post (http://stackoverflow.com/questions/19662713/where-do-i-find-the-bashrc-file-on-mac) said, but i don't see `.bashrc` listed...do i need create it? – 14wml Dec 01 '16 at 06:09
  • I also don't see `.bash_profile`. I only see `.bash_history` and `.bash_sessions` – 14wml Dec 01 '16 at 06:10
  • I don't know how your particular interactive `bash` shell is set up (and I don't know any MacOSX specific) and configured (that is system and computer specific). Probably you need to find out by yourself. I'm sure it is a FAQ. – Basile Starynkevitch Dec 01 '16 at 06:12
  • alright. thanks for taking the time to answer my question, im glad that i've narrowed down the problem! – 14wml Dec 01 '16 at 06:13
  • I added more links. I believe you should follow all of them. You are lacking some basic understanding about how your bash shell is working, and you need several hours to learn more about it. And understanding that is useful in general (not only for `opam` or `ocaml`) – Basile Starynkevitch Dec 01 '16 at 06:16
1

In general, homebrew puts all its binaries, libraries and settings in /usr/local/Cellar/PACKAGENAME/VERSIONNUMBER but it also creates symbolic links in /usr/local/bin that point to the latest package/version.

So, if you look at my /usr/local/bin you will see:

ls -l /usr/local/bin

Output

lrwxr-xr-x  1 mark  admin        26 30 Jan  2016 ack -> ../Cellar/ack/2.14/bin/ack
lrwxr-xr-x  1 mark  admin        43 11 Oct 13:30 amqp-consume -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-consume
lrwxr-xr-x  1 mark  admin        49 11 Oct 13:30 amqp-declare-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-declare-queue
lrwxr-xr-x  1 mark  admin        48 11 Oct 13:30 amqp-delete-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-delete-queue
lrwxr-xr-x  1 mark  admin        39 11 Oct 13:30 amqp-get -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-get
lrwxr-xr-x  1 mark  admin        43 11 Oct 13:30 amqp-publish -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-publish
lrwxr-xr-x  1 mark  admin        28 17 Jul 22:49 7z -> ../Cellar/p7zip/16.02/bin/7z
lrwxr-xr-x  1 mark  admin        29 17 Jul 22:49 7za -> ../Cellar/p7zip/16.02/bin/7za
lrwxr-xr-x  1 mark  admin        29 17 Jul 22:49 7zr -> ../Cellar/p7zip/16.02/bin/7zr
lrwxr

As you can see, ack points to version 2.14 of ack in the Cellar and so on.

In general therefore, when using homebrew, you should not directly use anything in the Cellar because that is version-specific. Instead, you should use /usr/local/bin and rely on that pointing to the latest/greatest thing in the Cellar. That way you won't have pain when upgrading and you won't have to change all your app-1.01 to app-1.0.2 in all your scripts because you will just be using app (which, by virtue of your PATH, means /usr/local/bin/app) instead of anything version-specific.

So, I would suggest you edit your bash profile, using TextEdit like this:

open -e ~/.profile

and add this line at the end:

export PATH=/usr/local/bin:$PATH

Remove all your version-specific aliases and log out and then back in again.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432