Hi all, I recently ran into a rather confusing (to me) problem with the
PATH in my
.bash_profile. It was suggested that I might post about it here.
In a failed attempt to get OpenMP working, I installed llvm with
brew install llvm. This didn’t play nicely with the compiler flags that I was using for arm64 architecture, and so after fiddling around blindly for a while, I eventually reinstalled llvm and then uninstalled it with
brew uninstall llvm.
After uninstalling, I was left in a state where the behavior of Stan, called from R (with or without Rstudio) depended on whether I opened R(studio) by double-clicking the icon in the
/Applications folder or opening it via Terminal with
open /Applications/Rstudio.app or
open /Applications/R.app. Instances opened by double clicking worked completely as expected. Instances opened from Terminal displayed the following behavior:
- failure to compile any c++, erroring with
error: can't exec '/opt/local/libexec/llvm-10/bin/clang++' (errno=NO such file or directory). This same error was also returned by Terminal when running, for example
cmdstanr::check_cmdstan_toolchain()indicated that the toolchain was set up properly.
- From R,
dirname(Sys.which("clang++"))(which is used by
- Setting the
~/.bash_profileto the above path (i.e.
export PATH="/opt/local/bin:$PATH"") didn’t change anything.
I needed to set the
PATH to “/usr/bin” (i.e.
export PATH="/usr/bin:$PATH"). This worked after an install of Xcode (not just Xcode command line tools), but I don’t have any reason to believe that the install of Xcode was necessary, except to help me troubleshoot (see below).
After installing Xcode, the output of R’s
dirname(Sys.which("clang++")) changed from
"/usr/bin", which was the path I needed.
I don’t know why R (both the versions that worked after launching by double-click and the versions that didn’t work after launching with terminal) initially returned
dirname(Sys.which("clang++")), but in any case I think this wasn’t the correct path. Then, the Terminal-launched instances of R were looking on my
PATH variable and going to
/opt/homebrew/bin, which was still trying to point to my uninstalled
llvm. Something like that anyway. Thanks to @ahartikainen who patiently helped me through parts of this.