简体   繁体   English

UnsatisfiedLinkError-如何创建c ++-DLL?

[英]UnsatisfiedLinkError - how to create the c++-DLL?

I am trying to generate a dll which I can access from java via JNA. 我正在尝试生成一个可以通过JNA从Java访问的dll。

I just try a simple one: 我只是尝试一个简单的方法:

CPP: CPP:

void Initialize()
{
  std::cout<< "Hello World!";
}

iostream is also included and after compiling I get: CreateDll.dll iostream也包括在内,编译后得到:CreateDll.dll

Via Visual Studio I can generate now a *.dll. 通过Visual Studio,我现在可以生成一个* .dll。

which I try loading into Java like: 我尝试将其加载到Java中,例如:

public class mainRoutine {
  public static void main(String[] args) {
    NativeWrapper INSTANCE = (NativeWrapper) Native.loadLibrary("CreateDll" , NativeWrapper.class);             
    INSTANCE.Initialize();
  }

  static {
    System.setProperty("jna.library.path", "C:\\workspace\\JNA");
  }
}

There is also another Interface: 还有另一个接口:

import com.sun.jna.Library; 导入com.sun.jna.Library;

public interface NativeWrapper extends Library {
  void Initialize();
}

So but now running the Java function I get the error, 因此,但是现在运行Java函数,我得到了错误,

 java.lang.UnsatisfiedLinkError: 
  Error looking up function 'Initialize': 
   The specified procedure could not be found.

What am I missing? 我想念什么?

PS: I know there are many topics, but trying for a day already I have not found the solution. PS:我知道有很多主题,但是已经尝试了一天,但没有找到解决方案。 Please help me. 请帮我。

Are you exporting the symbol: 您要导出符号吗?

void _declspec(dllexport) Initialize()
{
  std::cout<< "Hello World!";
}

You need to both export and (if using C++) un-decorate the function name. 您需要导出和(如果使用C ++)取消修饰函数名称。

On windows, functions are typically made available for export with __declspec(dllexport) . 在Windows上,通常可以使用__declspec(dllexport)导出函数。

On any platform, to ensure a function is exported in unmanagled form, you must use extern "C" . 在任何平台上,要确保以未处理的形式导出功能,必须使用extern "C"

Specifically: 特别:

extern "C" void __declspec(dllexport) Initialize() { ... }

There are other ways to designate exported functions, but this is probably the most common and straightforward to use. 还有其他方法可以指定导出的函数,但这可能是最常见和最直接的使用方法。 If you don't use extern "C" , your function will look something like InitializeZ@ASDF@ , where the additional garbage characters are used by the compiler and linker to make a given function uniquely recognizable based on its calling signature. 如果您使用extern "C" ,您的函数将类似于InitializeZ@ASDF@ ,在该函数中,编译器和链接器使用其他垃圾字符来使给定函数根据其调用签名唯一地识别。

What if there is a class to be implemented ? 如果要实现一个类怎么办? where the .h file looks like this: .h文件如下所示:

namespace simpleDLLNS
{
    class simpleDLL
    {
    public:

       char giveVoidPtrGetChar(void* param);
       int giveIntGetInt(int a);
       void simpleCall(void);
       int giveVoidPtrGetInt(void* param);
    };
}

Where should extern "C" void __declspec(dllexport) be used ? 应该在哪里使用extern“ C” void __declspec(dllexport)? I used it when implementing the functions. 我在实现功能时使用了它。 but when i opened the dll, it looked like this: 但是当我打开dll时,它看起来像这样:

?simpleCall@simpleDLL@simpleDLLNS@@QAEXXZ ?simpleCall @ simpleDLL @ simpleDLLNS @@ QAEXXZ

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UnsatisfiedLinkError:如何创建不同步的放气机? - UnsatisfiedLinkError: How to create an unsynchronized deflater? 另一个JNI,C ++,DLL,UnsatisfiedLinkError <Native Method> - Another JNI, C++, DLL, UnsatisfiedLinkError <Native Method> UnsatisfiedLinkError用SWIG包装C ++ DLL以允许Java开发人员使用它 - UnsatisfiedLinkError Wrapping C++ DLL with SWIG to allow Java developers to use it JNI C++ DLL -“UnsatisfiedLinkError: %1 不是有效的 Win32 应用程序” - JNI C++ DLL - 'UnsatisfiedLinkError: %1 is not a valid Win32 application' UnsatisfiedLinkError导出用于部署的dll - UnsatisfiedLinkError exporting a dll for deployment UnsatisfiedLinkError + JNLP + Applet + DLL - UnsatisfiedLinkError + JNLP + Applet + DLL 如何修复错误 UnsatisfiedLinkError: C:\Program Files\dtSearch Developer\bin\dtsjava.dll: 操作系统无法运行 %1 - How to Fix Error UnsatisfiedLinkError: C:\Program Files\dtSearch Developer\bin\dtsjava.dll: The operating system cannot run %1 IntelliJ java.lang.UnsatisfiedLinkError:C:\\ User \\…\\ java_bridge.dll:找不到依赖库 - IntelliJ java.lang.UnsatisfiedLinkError: C:\User\…\java_bridge.dll: Can't find dependent libraries Windows JNI 加载并执行 dll 中的 c++ 代码错误 Z93F725A07423FE1C889F448B33DsfiedLinkError:648B33DsfiedLinkError:6 - Windows JNI Loading and executing c++ code in dll error java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError:C:\\ opencv \\ build \\ java \\ x64 \\ opencv_java310.dll: - java.lang.UnsatisfiedLinkError: C:\opencv\build\java\x64\opencv_java310.dll:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM