zoukankan      html  css  js  c++  java
  • 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

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

  • 相关阅读:
    第七次作业
    rfid工作原理
    实验九——基本数据类型存储及应用总结
    实验八——函数定义及调用总结
    实验七——函数定义及调用总结
    作业
    作业
    作业
    开始
    实验12——指针的基础应用2
  • 原文地址:https://www.cnblogs.com/Jason-c/p/9619954.html
Copyright © 2011-2022 走看看