mach-o, but wrong architecture

Discussion in 'Mac Programming' started by dbrayford, Mar 17, 2010.

  1. dbrayford
    Expand Collapse
    macrumors member

    Joined:
    Feb 22, 2010
    #1
    I am getting a strange error message when trying to load a dylib I've just built.

    ../xxx.dylib: no suitable image found ../xxx.dylib: mach-o, but wrong architecture

    I don't understand the error message as I am trying to load the dynamic library on the same machine as I built it on.

    David
     
  2. Sayer
    Expand Collapse
    macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    Open the Terminal and use the 'lipo' command to inspect the binary.

    Use: lipo -info /path/to/dylib

    It will show you which architectures are in the file. If you only see PPC or something you dont have, that's the problem.

    Check your build settings for -arch flags to make sure you are building the dylib properly for your Mac.
     
  3. fernandovalente
    Expand Collapse
    macrumors 6502

    fernandovalente

    Joined:
    Aug 29, 2008
    Location:
    Third world **** hole, I mean, Brazil
    #3
    Make sure you're compiling both app and dylib to the same architecture. You may be compiling one for i386 an the other for X86_64.
     
  4. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #4
    Thanks,

    The compile line I used was:
    g++ -c -m64 -I

    The link line was:
    g++ -m64 -dynamiclib -o xxxx.dylib *.o

    I assumed that that it was building and linking to the same architecture.
     
  5. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    You are compiling your source and linking as a 64-bit binary. But is xxxx.dylib compiled as 64-bit?
     
  6. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #6
    I did lipo -info on the *.o files and the output was non-fat files architecture: x86_64

    I also performed the lipo -info on all the system dynamic libraries and they all have x86_64 version inside them.
     
  7. chown33
    Expand Collapse
    macrumors 604

    Joined:
    Aug 9, 2009
    #7
    Please post the actual command-line, and the actual output that shows the error.

    When you use placeholders like xxx.dylib, you're removing information that may be critical to solving the problem.
     
  8. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #8
    I added the the option -lx to the link line and this fixed the problem.
    I still don't understand how it was linking to the wrong libraries. I am a newbie to makefiles, as I always had a working makefile to work with.

    Thanks for all your help, it was most appreciated.
     
  9. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #9
    I was mistaken and the fix didn't work.

    Below is the message from the terminal.

    The first part is from the Java JNI as it is trying to load the dylib.

    UnsatisfiedLinkError e in loading libAvistoGL.dylib
    java.lang.UnsatisfiedLinkError: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: no suitable image found. Did find: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: mach-o, but wrong architecture
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1822)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1746)
    at java.lang.Runtime.loadLibrary0(Runtime.java:822)
    at java.lang.System.loadLibrary(System.java:993)
    at AvistoGL.<init>(AvistoGL.java:2716)
    at OGLCanvas.<init>(OGLCanvas.java:83)
    at CenterPanel.<init>(CenterPanel.java:28)
    at AvistoGLTest.<init>(AvistoGLTest.java:32)
    at AvistoGLTest.main(AvistoGLTest.java:55)
    null
    /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: no suitable image found. Did find: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: mach-o, but wrong architecture
    /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: no suitable image found. Did find: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib: mach-o, but wrong architecture
     
  10. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    So what does "lipo -info /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib" return?
     
  11. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #11
    Non-fat file: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib is architecture: x86_64
     
  12. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #12
    OK, cool. And you are trying to use this with JNI so it has to match the architecture of your java executable/process (as it will be loaded into that processes memory space). Can you lipo the java executable you are using?
     
  13. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #13
    lipo -info /Users/u0533750/Desktop/workspace/AvistoGL_Mac/AvistoGL.class
    lipo: truncated or malformed fat file (offset plus size of cputype (338758144) cpusubtype (1306377) extends past the end of the file) /Users/u0533750/Desktop/workspace/AvistoGL_Mac/AvistoGL.class
     
  14. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    You misunderstand. That is a class file. It is not an executable (it's java bytecode). The process that must match is the actual java executable. It's a file called java
     
  15. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #15
    I have several versions of the executable java. How do I determine which one is being called?

    Here is the output from the current

    lipo -info /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
    Architectures in the fat file: /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java are: ppc7400 i386 x86_64
     
  16. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #16
    In general type "which java". But, in this case, that may not work. You seem to be running some sort of large system. Does it have start-up script or something? As that may specify the java path...
     
  17. chown33
    Expand Collapse
    macrumors 604

    Joined:
    Aug 9, 2009
    #17
    If you're using a 'java ...' command-line to run your program, please post the exact command-line.

    If you're using a shell script or some other means to start Java, tell us exactly what that is.

    Also post the output of this command:
    Code:
    java -version
    
    Copy and paste the actual output.
     
  18. dbrayford
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 22, 2010
    #18
    java -version
    java version "1.5.0_20"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02-315)
    Java HotSpot(TM) Client VM (build 1.5.0_20-141, mixed mode, sharing)
     
  19. chown33
    Expand Collapse
    macrumors 604

    Joined:
    Aug 9, 2009
    #19
    This is the 32-bit Java 5 JVM. It can't load x86_64 jni libs.

    Is this on 10.5 Leopard, then? Because there isn't a Java 5 on Snow Leopard, only Java 6, unless you've installed the unsupported Java 5 from Leopard.

    And what is the command-line or shell-script or whatever you're actually using to run your program?

    If you specifically want 64-bit java, you must use the -d64 command-line option. Test case:
    Code:
    java -d64 -version
    
     
  20. okdt
    Expand Collapse
    macrumors newbie

    Joined:
    Jun 10, 2010
    #20
    Specify 32bit mode.

    This error occurs if you execute 32bit based binary on 64bit platform.

    So if you use Java, you may add -d32.
     
  21. DJRichCMusic
    Expand Collapse
    macrumors newbie

    Joined:
    Aug 31, 2010
    #21
    I am having a similar problem I wonder if anyone can help me.

    My Stack Trace:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/rcook/NetBeansProjects/MPX Print Suite/libEyeOneNative.dylib: no suitable image found. Did find: /Users/rcook/NetBeansProjects/MPX Print Suite/libEyeOneNative.dylib: mach-o, but wrong architecture
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1823)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1746)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at com.mpx.device.eyeone.EyeOneDevice.<init>(EyeOneDevice.java:25)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.mpx.plugin.device.PluginDeviceLoader.loadDevices(PluginDeviceLoader.java:52)
    at com.mpx.plugin.device.PluginDeviceLoader.getInstance(PluginDeviceLoader.java:29)
    at com.mpx.printsuite.TestDevicePlugin.main(TestDevicePlugin.java:22)

    Lipo:

    Non-fat file: libEyeOneNative.dylib is architecture: i386


    Java Version:

    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)



    Many thanks in advance.


    Regards

    Richard
     
  22. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #22
    Have you tried the fix in the thread (run in 32 bit mode)?
     
  23. DJRichCMusic
    Expand Collapse
    macrumors newbie

    Joined:
    Aug 31, 2010
    #23
    I have not tried this as the lib works for another java application on the same box.

    I just can't tell the difference.
     
  24. sirkencubin
    Expand Collapse
    macrumors newbie

    Joined:
    Dec 26, 2010
    #24
    help

    hi,

    I have a similar problem too. I would appreciate if you can help.

    Programme gives the following error

    Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: /Users/akdes/BicAT_v2.22/libisa.jnilib: no suitable image found. Did find: /Users/akdes/BicAT_v2.22/libisa.jnilib: mach-o, but wrong architecture

    lipo -info

    Non-fat file: /Users/akdes/BicAT_v2.22/libisa.jnilib is architecture: ppc

    java -version
    java version "1.5.0_26"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_26-b03-376-9M3263)
    Java HotSpot(TM) Client VM (build 1.5.0_26-156, mixed mode, sharing)

    Thanks a lot
     
  25. wrldwzrd89
    Expand Collapse
    macrumors G4

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #25
    You're trying to run a PPC-only JNILIB on an Intel version of Java. That's doomed to fail.
     

Share This Page