java.lang.UnsatisfiedLinkError将C ++函数映射到JNA

时间:2016-04-12 07:31:39

标签: java c++ dll jna jnaerator

我必须将本机C ++库映射到JNA,这是库头:

#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 

这是我用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();
        }
    };
}

这是DependencyWalker找到的导出函数:

(饰) enter image description here (未修饰的) enter image description here

当我尝试使用此配置运行测试时,我得到了:

  

线程中的异常" main" java.lang.UnsatisfiedLinkError:错误   查找功能' worm_readData'

为什么JNA找不到函数名?

0 个答案:

没有答案