问题
I'm creating a Photoshop Plug In on OS X (Basically a Bundle / DyLib).
I'm using Intel Compiler and uses OpenMP by linking against OpenMP (libiomp5
).
When I use Static Linking it crashes Photoshop (Only on OS X, on Windows it works).
So I tried dynamic linking.
The host, Photoshop, uses by itself libiomp5.dylib
which is available on its Framework folder.
So, on Xcode I set on the Linking Part the Runpath Search Paths
to @executable_path/../Frameworks/
yet when I try to load it on Photoshop it won't work.
I also tried to set Runpath Search Paths
to Intel Run Time Redistributable Libraries (Which include all DyLib needed for the Plug In according to MacDependency, just like Photoshop's Framework library) yet still it won't load on Photoshop.
When I use otool -L on the Plug In, I get:
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 157.0.0)
libimf.dylib (compatibility version 0.0.0, current version 0.0.0)
libsvml.dylib (compatibility version 0.0.0, current version 0.0.0)
libirng.dylib (compatibility version 0.0.0, current version 0.0.0)
libiomp5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
libintlc.dylib (compatibility version 1.0.0, current version 1.13.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0)
When I tried otool -l
on the Plug In I do see what I insert in Xcode:
Load command 6
cmd LC_UUID
cmdsize 24
uuid B61F2961-AD6D-30B9-AF58-C67689731966
Load command 7
cmd LC_VERSION_MIN_MACOSX
cmdsize 16
version 10.7
sdk 10.10
Load command 8
cmd LC_LOAD_DYLIB
cmdsize 88
name /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 157.0.0
compatibility version 2.0.0
Load command 9
cmd LC_LOAD_DYLIB
cmdsize 40
name libimf.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 0.0.0
compatibility version 0.0.0
Load command 10
cmd LC_LOAD_DYLIB
cmdsize 40
name libsvml.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 0.0.0
compatibility version 0.0.0
Load command 11
cmd LC_LOAD_DYLIB
cmdsize 40
name libirng.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 0.0.0
compatibility version 0.0.0
Load command 12
cmd LC_LOAD_DYLIB
cmdsize 40
name libiomp5.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 5.0.0
compatibility version 5.0.0
Load command 13
cmd LC_LOAD_DYLIB
cmdsize 48
name /usr/lib/libc++.1.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 120.0.0
compatibility version 1.0.0
Load command 14
cmd LC_LOAD_DYLIB
cmdsize 56
name /usr/lib/libSystem.B.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 1213.0.0
compatibility version 1.0.0
Load command 15
cmd LC_LOAD_DYLIB
cmdsize 40
name libintlc.dylib (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 1.13.0
compatibility version 1.0.0
Load command 16
cmd LC_LOAD_DYLIB
cmdsize 104
name /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (offset 24)
time stamp 2 Thu Jan 1 02:00:02 1970
current version 62.0.0
compatibility version 1.0.0
Load command 17
cmd LC_RPATH
cmdsize 48
path @executable_path/../Frameworks/ (offset 12)
Load command 18
cmd LC_FUNCTION_STARTS
cmdsize 16
dataoff 3486976
datasize 5616
Load command 19
cmd LC_DATA_IN_CODE
cmdsize 16
dataoff 3492592
datasize 0
If I set the Runpath Search Paths
to Intel Run Time Redistributable Libraries I see the proper path as well, yet the result is the same.
Could anyone assist me with that?
I'm not very experience developer so, step by step would be great.
回答1:
Your solution is correct for modern libraries that are aware of @rpath. OpenMP library supports @rpath starting compiler version 16.0 update 2. In your case your RPATH settings are ignored by system
Can you try to link with the with openmp library from photoshop? as I understand they did a workaround for this and updated install_name from libiomp5.dylib to "@executable_path/../Frameworks/libiomp5.dylib". so if you link to that library the openmp name in "otool -l" output will be changed to @executable_path/../Frameworks/libiomp5.dylib
some hints
If photoshop updates install name via install_name_tool
$ otool -l ./a.out | grep omp name libiomp5.dylib (offset 24) # libiomp5.dylib was copied to the location with test $ install_name_tool -id "@executable_path/../Frameworks/libiomp5.dylib" libiomp5.dylib $ LIBRARY_PATH=.:$LIBRARY_PATH icc -openmp test1.cpp $ otool -l ./a.out | grep omp name @executable_path/../Frameworks/libiomp5.dylib (offset 24)
RPATH usage
install_name_tool -id "@executable_path/../Frameworks/libiomp5.dylib" libiomp5.dylib $ LIBRARY_PATH=.:$LIBRARY_PATH icc -openmp test1.cpp -Wl,-rpath,. $ ./a.out dyld: Library not loaded: @executable_path/../Frameworks/libiomp5.dylib Referenced from: /nfs/inn/home/vpolin/mac/./a.out Reason: image not found Trace/BPT trap: 5 $ install_name_tool -id "@rpath/libiomp5.dylib" libiomp5.dylib $ LIBRARY_PATH=.:$LIBRARY_PATH icc -openmp test1.cpp -Wl,-rpath,. $ otool -l ./a.out | grep omp name @rpath/libiomp5.dylib (offset 24) $ ./a.out 4 8 8 8 8
--Vladimir
来源:https://stackoverflow.com/questions/40318465/setting-the-search-path-for-plug-in-bundle-dylib