Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

fernandovalente

macrumors 6502
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

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.
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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.
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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.
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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.
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
Non-fat file: /Users/u0533750/Desktop/workspace/AvistoGL_Mac/libAvistoGL.dylib is architecture: x86_64
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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?
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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...
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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

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.
 

dbrayford

macrumors member
Original poster
Feb 22, 2010
41
0
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)
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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)

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
 

okdt

macrumors newbie
Jun 10, 2010
1
0
Specify 32bit mode.

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

So if you use Java, you may add -d32.
 

DJRichCMusic

macrumors newbie
Aug 31, 2010
4
0
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
 

DJRichCMusic

macrumors newbie
Aug 31, 2010
4
0
I have not tried this as the lib works for another java application on the same box.

I just can't tell the difference.
 

sirkencubin

macrumors newbie
Dec 26, 2010
1
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.