5

Sorry for the prolix post; see tl;dr at the end.

I'm running macOS Catalina. I'm trying to install some packages in R (4.0.3) running in Rstudio (1.3.1093), but I keep oscillating between two different errors, both having to do with openssl.

I understand that the openssl that R wants to install is a wrapper for the system library of the same name. When I try to install, say, openssl, in Rstudio, I get the following error:

Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/local/include
--------------------------- [ANTICONF] --------------------------------\
Configuration failed because openssl was not found. Try installing:\
 \* deb: libssl-dev (Debian, Ubuntu, etc)\
 \* rpm: openssl-devel (Fedora, CentOS, RHEL)\
 \* csw: libssl_dev (Solaris)\
 \* brew: openssl@1.1 (Mac OSX)\
If openssl is already installed, check that 'pkg-config' is in your\
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config\
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:\
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'\
-------------------------- [ERROR MESSAGE] ---------------------------\
tools/version.c:1:10: fatal error: 'openssl/opensslv.h' file not found\
#include <openssl/opensslv.h>\
1 error generated. 

That's strange because when I go to the terminal and run \

which openssl

I get

/usr/bin/openssl

and when I run, also in the terminal,

locate opensslv.h

one of the items returned is

/usr/local/include/openssl/opensslv.h

Though it turns out that is a soft link which points to something I deleted. OK, so I change the soft link and have it point to another openssl/opensslv.h file elsewhere on my system (there sure are a lot of openssl packages on my system, mostly having to do with rails or anaconda). After that I try running

install.packages("openssl")

in Rstudio and this time I get a new error:

Error: package or namespace load failed for ‘openssl’ in dyn.load(file, DLLpath = DLLpath, ...):\
 unable to load shared object '/usr/local/lib/R/4.0/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so':\
  dlopen(/usr/local/lib/R/4.0/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so, 6): Symbol not found: _EVP_PKEY_get_raw_private_key\
  Referenced from: /usr/local/lib/R/4.0/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so\
  Expected in: flat namespace\
 in /usr/local/lib/R/4.0/site-library/00LOCK-openssl/00new/openssl/libs/openssl.so\
Error: loading failed\
Execution halted

If I do things more sensibly by installing openssl with brew and changing the opensslv.h soft link to point to the opensslv.h installed by brew, I get the same error when installing openssl in R (either in Rstudio or by running R in the terminal)

From what I've read online, that last R error (the package r namespace load failed one) has to do with multiple openssl versions on my system. And yes, I have a ton of openssl versions of my system (using locate and grep shows that I have 212 copies of openssl on my system) but the vast majority of those are from anaconda, ruby, or node, and the only one that looks like it's in my PATH is /usr/bin/openssl, which is read-only on later versions of macOS, btw.

So my question is A) Do I have too many versions of openssl in my PATH and B) how can I find them all?

Please don't judge my systems management; I've been doing stupid things trying to get these R packages installed and now I'm afraid I've dug a hole too deep to climb out of!

tl;dr: If I have multiple versions of a systems library (e.g. openssl) installed in my PATH in macOS, how can I find where they all are? Maybe something like linux's

ldconfig -p|grep openssl
Phil
  • 7,287
  • 3
  • 36
  • 66
Brian Wray
  • 125
  • 1
  • 8
  • 1
    Hi @Brian-Wray, hope you've figured this out by now, but if you want to locate brew openssl try `echo $(brew --prefix openssl)` in your terminal, then add two lines to your `~/.R/Makevars` file with the output, e.g. (if the output of the command is `/usr/local/opt/openssl@1.1`) add `LDFLAGS=-L/usr/local/opt/openssl@1.1/lib` and `CPPFLAGS=-I/usr/local/opt/openssl@1.1/include` on seperate lines in your Makevars file. To compile packages from source in macOS Big Sur, see my instructions here: https://stackoverflow.com/a/65334247/12957340 – jared_mamrot Dec 22 '20 at 05:09
  • 2
    Dear @jared_mamrot, I can't thank you enough for your advice here. After running that echo command and appending the two lines to ~/.R/Makevars I was able to successfully install the packages I was struggling with. Installation worked for me with a simple install.packages command in R studio, i.e. no need to compile from source. If I had 2 upvotes to give I would gladly do so! – Brian Wray Jan 04 '21 at 16:03
  • Glad you got it working! I'll make my comment into an answer that you can [accept](https://meta.stackexchange.com/a/5235) – jared_mamrot Jan 04 '21 at 21:30

1 Answers1

7

To locate brew openssl use echo $(brew --prefix openssl) in your terminal, then add two lines to your ~/.R/Makevars file with the output, e.g. if the output of the command is /usr/local/opt/openssl@1.1, add

LDFLAGS=-L/usr/local/opt/openssl@1.1/lib
CPPFLAGS=-I/usr/local/opt/openssl@1.1/include

to your ~/.R/Makevars file.

To compile packages from source in macOS Big Sur, see my instructions here

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
  • how can I get to ~/.R/Makevars file? I cannot find it. – user2746087 May 20 '21 at 02:18
  • If you don't have a file called "Makevars" in the ~/.R directory you can create one (e.g. `echo LDFLAGS=-L/usr/local/opt/openssl@1.1/lib > ~/.R/Makevars && echo CPPFLAGS=-I/usr/local/opt/openssl@1.1/include >> ~/.R/Makevars`) – jared_mamrot May 20 '21 at 03:45
  • Ok, I ran the commands and a file was created with these lines. However, running the code again gave me the same error: `Warning: Error in dyn.load: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/openssl/libs/openssl.so': Reason: image not found [No stack trace available]` For context, this is a shiny app. The error seems to be triggered when a piece of code tries to connect to mongodb to write data. Running `echo $(brew --prefix openssl)` gives me `/usr/local/opt/openssl@1.1` Any ideas? Thanks. – user2746087 May 20 '21 at 05:24
  • If you want help troubleshooting, I've created a room in chat (https://chat.stackoverflow.com/rooms/232622/troubleshoot-openssl-issues) – jared_mamrot May 20 '21 at 05:24
  • 2
    **Note::**`echo $(brew --prefix openssl)` for me yields `/opt/homebrew/opt/openssl@3`, but I still use `openssl@1.1` and not `opensssl@3` in my Makevars file – alexwhitworth Jul 16 '22 at 14:56