[Mono-osx] P/Invoke: Can't find dylib no matter what my configuration is

Kibiz0r kibiz0r at gmail.com
Sat Feb 13 13:59:11 EST 2010


Here's one I can successfully p/invoke:

otool -L /opt/local/lib/liballeg.dylib
/opt/local/lib/liballeg.dylib:
/opt/local/liballeg-4.2.dylib (compatibility version 4.2.0, current version
4.2.3)
 /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility
version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility
version 2.0.0, current version 152.0.0)
 /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility
version 1.0.0, current version 275.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
125.0.0)
 /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio
(compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit
(compatibility version 1.0.0, current version 1.0.0)
 /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox
(compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime
(compatibility version 1.0.0, current version 1591.3.0)
 /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version
227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
(compatibility version 1.0.0, current version 44.0.0)
 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
(compatibility version 150.0.0, current version 550.13.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.14.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility
version 45.0.0, current version 1038.25.0)

Here's the output from running my app with logging (good to know how to
do!):

MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono AllegroSharp.Sandbox.exe
Mono-INFO: DllImport attempting to load:
'/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading location: 'lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library: 'dlopen(lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading library: './lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library 'dlopen(./lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading: '/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(/usr/local/lib/liballegro-4.9.16.dylib, 9): no suitable image found.
 Did find:
 /usr/local/lib/liballegro-4.9.16.dylib: mach-o, but wrong architecture'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading location: 'lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library: 'dlopen(lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading library: './lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library 'dlopen(./lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading: 'lib/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib, 9): image not found'.

(AllegroSharp.Sandbox.exe:288): Mono-WARNING **: DllImport unable to load
library 'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib, 9): image not
found'.
Mono-INFO: DllImport attempting to load:
'/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading location: 'lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library: 'dlopen(lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading library: './lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library 'dlopen(./lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading: '/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(/usr/local/lib/liballegro-4.9.16.dylib, 9): no suitable image found.
 Did find:
 /usr/local/lib/liballegro-4.9.16.dylib: mach-o, but wrong architecture'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading location: 'lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library: 'dlopen(lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading location:
'lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library:
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.dylib, 9): image not
found'.
Mono-INFO: DllImport loading library: './lib/usr/local/lib/
liballegro-4.9.16.dylib.so'.
Mono-INFO: DllImport error loading library 'dlopen(./lib/usr/local/lib/
liballegro-4.9.16.dylib.so, 9): image not found'.
Mono-INFO: DllImport loading library:
'./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle'.
Mono-INFO: DllImport error loading library
'dlopen(./lib/usr/local/lib/liballegro-4.9.16.dylib.bundle, 9): image not
found'.
Mono-INFO: DllImport loading: 'lib/usr/local/lib/liballegro-4.9.16.dylib'.
Mono-INFO: DllImport error loading library
'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib, 9): image not found'.

(AllegroSharp.Sandbox.exe:288): Mono-WARNING **: DllImport unable to load
library 'dlopen(lib/usr/local/lib/liballegro-4.9.16.dylib, 9): image not
found'.

Unhandled Exception: System.DllNotFoundException:
/usr/local/lib/liballegro-4.9.16.dylib
  at (wrapper managed-to-native) AllegroSharp.Allegro:GetVersion ()
  at AllegroSharp.Sandbox.MainClass.Main (System.String[] args) [0x00000] in
<filename unknown>:0

I'm assuming wrong architecture means the library was built 64-bit but
should be 32. (or vice-versa?) I'm on snow leopard. This sounds more like a
build system issue than a p/invoke issue, so I'll pursue this with the
Allegro developers. Thanks for your help.

On Sat, Feb 13, 2010 at 4:40 AM, Laurent Etiemble <
laurent.etiemble at gmail.com> wrote:

> Hello,
>
> The first line of the otool output seems suspicious: usually, the first
> line is the absolute path of the library, or contains a path lookup
> directive (@executable_path for example).
>
> - Can you post the otool output of a library that you can successfully
> p/invoke ?
> - Have you tried to use the following command line to see what is going on
> ?
>
> MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono MyProgram.exe
>
> Regards, Laurent Etiemble.
>
> 2010/2/13 Kibiz0r <kibiz0r at gmail.com>
>
>>  I'm at my wit's end. I can p/invoke other dylibs just fine, and I can
>> use this dylib just fine from C, but something isn't working here.
>>
>> The dylib is here: /usr/local/lib/liballegro-4.9.16.dylib
>>
>> My binding looks like this:
>> public class Allegro
>> {
>>     [DllImport("allegro-4.9.16.dll", EntryPoint =
>> "al_get_allegro_version")]
>>     public static extern uint GetVersion();
>> }
>>
>> And I've got a .config like this:
>> <dllmap dll="allegro-4.9.16.dll"
>> target="/usr/local/lib/liballegro-4.9.16.dylib" os="osx" />
>>
>> When I try to do Allegro.GetVersion(), I get System.DllNotFoundException:
>> /usr/local/lib/liballegro-4.9.16.dylib
>>
>> This is the output from otool -L /usr/local/lib/liballegro-4.9.16.dylib:
>> /usr/local/lib/liballegro-4.9.16.dylib:
>> liballegro-4.9.16.dylib (compatibility version 0.0.0, current version
>> 0.0.0)
>> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
>> (compatibility version 45.0.0, current version 1038.25.0)
>>  /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
>> (compatibility version 1.0.0, current version 275.0.0)
>> /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
>> (compatibility version 1.0.0, current version 1.0.0)
>>  /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility
>> version 1.0.0, current version 1.0.0)
>> /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version
>> 7.9.0)
>>  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
>> 125.0.0)
>>
>> I've tried using various combinations of DllImport and dllmap, but nothing
>> works.
>> I tried setting DYLD_LIBRARY_PATH, but that didn't help. (I can p/invoke
>> other dylibs from the same directory anyway.)
>>
>> --
>> Michael Harrington | Software Apprentice
>> Atomic Object | http://atomicobject.com
>> [Ph] +1 616 776 6020 [Fx] +1 616 776 6015
>>
>> _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
>>
>>
>


-- 
Michael Harrington | Software Apprentice
Atomic Object | http://atomicobject.com
[Ph] +1 616 776 6020 [Fx] +1 616 776 6015
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20100213/9710b30e/attachment-0001.html 


More information about the Mono-osx mailing list