Skip to main content

cannot load library with jna

1 reply [Last post]
scott1256ca
Offline
Joined: 2008-10-19

Bit of background
I wanted to try something using ffmpeg and ffmpeg-java, which uses jna to access the ffmpeg functions. I haven't done much programming in the last few years, and very little java.

Anyway, I compiled ffmpeg to dll's using mingw and tried to run some of the ffmpeg-java programs but get 'can't load library' errors.

So went to the jna tutorials:

The code at the end will work if I copy msvcrt.dll to avformat.dll (so it isn't just a PATH problem). You will notice I replaced msvcrt with avformat, just to test. BTW it works if I use msvcrt and that dll is not in the current working directory.

If I copy the correct avformat.dll (or any of the others I compiled) to the same name, I get
java -Djna.library.path=. -cp lib/jna.jar:. HelloWorld

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'avformat': The specified module could not be found.

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:127)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:170)
at com.sun.jna.Library$Handler.(Library.java:123)
at com.sun.jna.Native.loadLibrary(Native.java:260)
at com.sun.jna.Native.loadLibrary(Native.java:246)
at HelloWorld$CLibrary.(HelloWorld.java:11)
at HelloWorld.main(HelloWorld.java:19)

If I copy (for example) msihnd.dll to avformat.dll I get
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'printf': The specified procedure could not be found.
Now under the circumstances, this one makes sense, because I don't expect to find printf in there anyway, but I don't understand why the other dll's are not recognized.
Are the gcc generated dll's malformed? Is there some header information you can get into a dll compiled via gcc? Or any ideas how I can solve this?

other relevent info
XP SP2
java jdk_1.6.0_10
gcc is 4.2.1
jna is one I downloaded yesterday.
ffmpeg is 15261
mingw is 3.15

Thanks

Scott
========================================
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/** Simple example of native library declaration and usage. */
public class HelloWorld {

public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "avformat" : "c"),
CLibrary.class);

void printf(String format, Object... args);
}

public static void main(String[] args) {
CLibrary.INSTANCE.printf("Hello, World\n");
for (int i=0;i < args.length;i++) {
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
}
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
scott1256ca
Offline
Joined: 2008-10-19

Well, I messed around some more, and I think that there is a dependency on the libraries and they are being loaded in the wrong order (not the helloworld example, but ffmpeg-java).

It is too late for me to look much further, maybe tomorrow.