java.lang.UnsatisfiedLinkError Mapping C++ functions to JNA

218 views Asked by At

I have to map a native C++ library to JNA, this is the library header:

#ifndef WORMDLL_H
#define WORMDLL_H

#pragma once


#ifdef WORMDLL_EXPORTS
#define WORMDLL_API __declspec(dllexport) 
#else
#define WORMDLL_API __declspec(dllimport) 
#endif

#include "wormError.h"

typedef BYTE WORM_DATA;

WORMDLL_API WORM_ERROR  worm_readData(const char* mountPoint, WORM_DATA *data,const unsigned int offset,const unsigned int numBlocks);
#endif 

And this is my mapping made with JNAeator:

package test;
import com.ochafik.lang.jnaerator.runtime.LibraryExtractor;
import com.ochafik.lang.jnaerator.runtime.MangledFunctionMapper;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import java.nio.ByteBuffer;

public interface TestLibrary extends Library {
    public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("test", true, TestLibrary.class);
    public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(TestLibrary.JNA_LIBRARY_NAME, MangledFunctionMapper.DEFAULT_OPTIONS);
    public static final TestLibrary INSTANCE = (TestLibrary)Native.loadLibrary(TestLibrary.JNA_LIBRARY_NAME, TestLibrary.class, MangledFunctionMapper.DEFAULT_OPTIONS);


    TestLibrary.WORM_ERROR worm_readData(String mountPoint, ByteBuffer data, int offset, int numBlocks);

    public static class WORM_ERROR extends PointerType {
        public WORM_ERROR(Pointer address) {
            super(address);
        }
        public WORM_ERROR() {
            super();
        }
    };
}

And this is the exported function found by DependencyWalker:

(decorated) enter image description here (undecorated) enter image description here

When I try to run a test with this configuration I got:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'worm_readData'

Why JNA cannot find functions names?

0

There are 0 answers