Hi all,

Thanks for the suggestions.  I solved my issue.  Here is what I've gathered:

First, Marc Schwartz noted that OSX GUI based apps do not inherit the shell environment. This is true apparently unless the app is started specifically from the command line, via e.g.:

open /Applications/R.app

If the app is started this way, then it WILL inherit the shell environment.  So I believe this explains why it works to export the path on the command line before opening the GUI app on the (same) command line window.  I assume that this also means that one could just put the export command in your .bash_profile (or /etc/profile if we want to make it true for all users), and then you'd only have to start R.app from the command line (though I haven't directly tried this).  Whether this could adversely affect other apps started this way (since they would then all inherit that same environment variables whether or not they were appropriate for them) I'm not sure.

OK, so how DO you get an OSX GUI app to inherit an environment variable?  There are a few ways that I gleaned from the links Steve Lianoglou provided. One is to create/edit /etc/launchd.conf and put your environment variable in it.  So for me, this file just needed to look like this:

setenv DYLD_FALLBACK_LIBRARY_PATH /Library/Frameworks/R.framework/Resources/lib

Note that there are no "=" signs, etc.  You can also put other environment variables in there that you'd like to have every OSX GUI app inherit (see http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x for more details).  You then either have to restart, or do:

grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl

in the command line to get these environment variables listed in your /etc/launchd.conf to be applied.

An alternative method is to install a preference pane called "EnvPane" (http://diaryproducts.net/EnvPane), which Steve Lianoglou pointed me to. This allows you to globally set environment variables through a GUI in your system preferences. The R.app (and presumably all GUI apps) inherit these variables.


One fly in the ointment: although both of these worked (in both cases R.app now respects my DYLD_FALLBACK_LIBRARY_PATH), I now get an annoying misleading (to someone with my level of understanding) warning message whenever terminal windows open:

"dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/login) is setuid or setgid"

I've poked around about this a bit, but haven't found out why this happens, or how to fix it (other than not setting DYLD_FALLBACK_LIBRARY_PATH). However, it doesn't seem to affect my particular issue. R.app inherits the DYLD_FALLBACK_LIBRARY_PATH that I want it to, and works as I had hoped.

If anyone has any ideas about how to deal with the "dyld: DYLD_ environment variables being ignored…" warning in my terminal window, please let me know. The initial google search hits about this message didn't seem to apply to my situation, and I didn't see any fixes.

One last thing I don't understand is that putting the path command in .Renviron does indeed lead R.app to report that this environment variable is "set", but it is in fact not set (or at least isn't being invoked with I call my package with the library() command). I put:

DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/R.framework/Resources/lib

Into .Renviron.  When I restart R.app, it does seem to have this set:

> Sys.getenv()
                                    DYLD_FALLBACK_LIBRARY_PATH 
               "/Library/Frameworks/R.framework/Resources/lib"  

However, when I call my package with library(), it doesn't respect this (it acts as if it doesn't know what DYLD_FALLBACK_LIBRARY_PATH is).  I'm not sure if this is a bug, or what. I certainly makes little sense on the surface.

In any case, thanks for all the suggestions!

-Tom

 

On Aug 8, 2013, at 5:01 PM, Steve Lianoglou <mailinglist.honeypot@gmail.com> wrote:

> Hi,
> 
> On Thu, Aug 8, 2013 at 1:42 PM, Tom Schoenemann <toms@indiana.edu> wrote:
>> Hello,
>> 
>> I am trying to get a custom R package (from another group) to run on my system. If I call it from the command line r, it works fine.  If I call it from R.app, it complains with:
>> 
>> Error in dyn.load(file, DLLpath = DLLpath, ...) :
>>  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.0/Resources/library/ANTsR/libs/libRantsRegistration.so':
>>  dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/ANTsR/libs/libRantsRegistration.so, 6): Library not loaded: libitkdouble-conversion-4.5.1.dylib
>>  Referenced from: /Applications/image-processing/ANTsR/src/ANTS/ANTS-build/lib/libl_antsRegistration.dylib
>>  Reason: image not found
>> Error: package or namespace load failed for ‘ANTsR’
>> 
>> (ANTsR is the package I'm trying to get working)
>> 
>> I CAN get it to work by doing this on the command line first:
>> 
>> export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/R.framework/Resources/lib
>> 
>> and then also opening the R.app from the command line:
>> 
>> open /Applications/R.app/
>> 
>> However, I can't seem to get R.app to know about
>> export DYLD_FALLBACK_LIBRARY_PATH=/Library/Frameworks/R.framework/Resources/lib
>> unless I do it this way.
>> 
>> So my questions are:
>> 
>> 1) how can I get R.app to know about the DYLD_FALLBACK_LIBRARY_PATH?  I tried putting it into my .Renviron file, but it doesn't work  (maybe the syntax is supposed to be different?)
>> 
>> 2) why does r on the command line know about dynamic libraries, but R.app does not?? This seems like a bug, but maybe there is a good reason for it?
> 
> I believe this is due to the phenomenon explained here:
> http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x
> 
> Look for the answer that starts with "Up to and including Lion"
> 
> Also you'll find a link to a free preference pane you can install that
> lets you handle these things with a GUI (pref pane) -- I've never used
> it, but you can find it here:
> 
> http://diaryproducts.net/EnvPane
> https://github.com/hschmidt/EnvPane
> 
> You could also try to manually set the environment variable in your
> working R session, via:
> 
> R> Sys.setenv(DYLD_FALLBACK_LIBRARY_PATH="/Library/Frameworks/R.framework/Resources/lib")
> 
> not sure if that'll work, but easy enough to try before.
> 
> Still -- it's possible that DYLD vars won't work in this way. See this:
> http://support.apple.com/kb/TS4267
> 
> Sorry -- no concrete answers here, but hopefully these things will
> help you find a workable solution.
> 
> -steve
> 
> -- 
> Steve Lianoglou
> Computational Biologist
> Bioinformatics and Computational Biology
> Genentech

_________________________________________________
P. Thomas Schoenemann

Associate Professor
Department of Anthropology
Cognitive Science Program
Indiana University
Bloomington, IN  47405
Phone: 812-855-8800
E-mail: toms@indiana.edu

Open Research Scan Archive (ORSA) Co-Director
Consulting Scholar
Museum of Archaeology and Anthropology
University of Pennsylvania

http://www.indiana.edu/~brainevo











	[[alternative HTML version deleted]]

