Tuesday, March 09, 2010

Custom Quartz Composer Patches: How to include a shared library

I have been struggling a little bit to make my "DataMatrixDecoder" patch load libdmtx as a shared library.

Actually it is pretty simple:
instead of the @executable_path, the install name needs to contain @loader_path.

Here some tools that can help you to make things work and check that things worked out the intended way (credits go to Mac OS X Hacking Tools):
1) install_name_tool to change recorded install names of a mach-o-binary.

2) lipo: to check if the universal binary magic worked out e.g.:
orion:Release wimpi$ lipo -detailed_info QuartzDM.plugin/Contents/MacOS/QuartzDM 
Fat header in: QuartzDM.plugin/Contents/MacOS/QuartzDM
fat_magic 0xcafebabe
nfat_arch 3
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    offset 4096
    size 18872
    align 2^12 (4096)
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    offset 24576
    size 21460
    align 2^12 (4096)
architecture ppc7400
    cputype CPU_TYPE_POWERPC
    cpusubtype CPU_SUBTYPE_POWERPC_7400
    offset 49152
    size 21956
    align 2^12 (4096)
3) otool to check and display info about the mach-o-binary like it's dependencies. e.g.
orion:Release wimpi$ otool -L QuartzDM.plugin/Contents/MacOS/QuartzDM 
QuartzDM.plugin/Contents/MacOS/QuartzDM:
 /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
 /System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0)
 @loader_path/libdmtx.dylib (compatibility version 1.0.0, current version 1.0.0)
 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 123.0.0)
 /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.0.0)
 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
 /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.0.0)

0 comments:

Post a Comment