从Excel 2016 for mac调用自定义共享库

时间:2016-08-29 22:50:13

标签: excel macos

我认为沙盒已添加到OSX上的Excel 2016加载项中。这会破坏其标头函数中的加载项来自共享库。如,像:

Option Explicit
#If Mac Then
Private Declare Function PropsSI_private Lib "libCoolProp.dylib" Alias "PropsSI" (ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal Ref As String) As Double
...

因为在加载项加载时,我们无法在尝试加载共享库之前调用任何函数。

以前我们只需要确保正确的共享库在〜/ lib中,但不再有效。我们如何修改加载项以允许我们调用共享库?

1 个答案:

答案 0 :(得分:1)

事实证明,答案是您需要将共享库放在/Users/${USER}/Library/Group Containers/UBF8T346G9.Office中,并确保将此文件夹添加到系统路径中。一种方法是将这些内容保存为文件~/Library/LaunchAgents/my.startup.plist(显然用适当的用户名替换ihb

<?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/ihb/Library/Group Containers/UBF8T346G9.Office"</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>