Skip to main content

cannot load library with jna

1 reply [Last post]
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(
at com.sun.jna.NativeLibrary.getInstance(
at com.sun.jna.Library$Handler.(
at com.sun.jna.Native.loadLibrary(
at com.sun.jna.Native.loadLibrary(
at HelloWorld$CLibrary.(
at HelloWorld.main(

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
java jdk_1.6.0_10
gcc is 4.2.1
jna is one I downloaded yesterday.
ffmpeg is 15261
mingw is 3.15


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"),

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.
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.