简体   繁体   中英

Setting DYLD_LIBRARY_PATH on Mac OS X Sierra (CoolProp)

Disclaimer: This question started as a GitHub issue .

Question

I'll put the X question right up front: Does anyone know a way to set DYLD_LIBRARY_PATH in a way that Excel 2016 will recognize on MacOS Sierra?

The actual problem (Y): How (else) can the developers of CoolProp allow their dynamic library to be used in Excel?

Background

I am trying to get Excel 2016 for Mac to recognize the CoolProp plugin using these instructions , which basically boil down to using this startup.plist :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.startup</string>
<key>ProgramArguments</key>
<array>
  <string>sh</string>
  <string>-c</string>
  <string>launchctl setenv DYLD_LIBRARY_PATH "/Users/$USER/Library/Group Containers/UBF8T346G9.Office"</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

to set DYLD_LIBRARY_PATH to a location where Excel can access the dynamic library and copying the libCoolProp.dylib file into that same directory. Unfortunately, it appears that due to SIP, one can no longer set any environment variable which starts with DYLD_ .

To verify this, I have built a test spreadsheet which contains this VBA function and =ENV("DYLD_LIBRARY_PATH") in cell A1.

Public Function Env(Value As Variant) As String
    Env = Environ(Value)
End Function

I observe this behaviour:

$ launchctl setenv DYLD_LIBRARY_PATH "/Users/${USER}/Library/Group Containers/UBF8T346G9.Office"
$ launchctl getenv DYLD_LIBRARY_PATH  # empty output
$ launchctl setenv DYLDLIBRARYPATH "/Users/${USER}/Library/Group Containers/UBF8T346G9.Office" # Same kind of thing, but no underscores
$ launchctl getenv DYLDLIBRARYPATH # works fine
/Users/alchemyst/Library/Group Containers/UBF8T346G9.Office

After running this sequence of commands in my terminal and restarting Excel, I am able to retrieve the contents of "DYLDLIBRARYPATH" using the test spreadsheet. I have also edited the startup.plist and obtained similar results. I appear to be following all the right steps, but it appears that "DYLD_*" is simply not being set when I call setenv. The result is the same if I do it as root.

So basically I am looking for any way in which I can still use this plugin on the Mac.

Versions: MacOS Sierra (10.12.3), Excel 2016 (15.32), CoolProp 6.10

due to SIP, one can no longer set any environment variable which starts with DYLD_

Yes and no. SIP protects Apple binaries from DYLD_ ; Microsoft's Excel is not protected by SIP and DYLD_INSERT_LIBRARIES works as expected.

How do we know this?

There's a library, libGMalloc.dylib that can be used to monitor debug allocations of applications. From the terminal, execute the following: -

DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib /Applications/Microsoft\ Excel.app/Contents/MacOS/Microsoft\ Excel

You'll see that Excel is launched and works, though a little slower than usual, due to the overhead of the inserted library that's busy monitoring all memory allocations.

In addition, using Activity Monitor and looking at the Excel process's open files, we can clearly see the libGMalloc.dylib that has been inserted into its process.

在此处输入图片说明

I suggest using DYLD_INSERT_LIBRARIES instead of DYLD_LIBRARY_PATH and referencing the Coolprop library from the command line, as demonstrated here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM