unity 调用 .dll 或 .so时遇到的问题

1、32位的 .dll 无法在64位的unity编辑器下运行。

System.DllNotFoundException: xxx  , 64位的程序运行32位的dll是会报这种错

2、Failed to load 'Assets/Plugins/xxx.dll', expected x64 architecture, but was x86 architecture. You must recompile your plugin for x64 architecture.

将CPU选择.dll对应的CPU

3、System.EntryPointNotFoundException:Unable to find an entry point

原因就是:c++源代码中的函数在编译成DLL后,函数的名称就发生了改变:会在函数的前后产生一些字符。所以找不到方法的入口点。

    [DllImport(dllName, EntryPoint = "?Free@@YAHXZ")]
    private static extern int Free();

  

Free的名字编译为dll时,变成了  ?Free@@YAHXZ  ,猜想可能的原因是直接写的C++接口,而不是C接口

即,可能是没有通过 extern "C" int _DLLExport Free(); 的形式封装。

也可再强制一下编码格式 CharSet = CharSet.Unicode

即,

[DllImport(dllName, EntryPoint = "?Free@@YAHXZ",CharSet = CharSet.Unicode)]
    private static extern int Free();

  

附:eXeScope是查看 dll、exe等编译后的名字的小工具,很好用,下载地址:https://download.csdn.net/download/jasonczy/10657046

在导出里就可以看到对应的名字了。

 

posted on 2018-09-10 15:21  Jason_c  阅读(7402)  评论(0编辑  收藏  举报