简体   繁体   English

在Mac上使用Mono中的DllImport进行DllNotFoundException

[英]DllNotFoundException with DllImport in Mono on Mac

I'm trying to use DLLImport in my Mono Mac project in order to use my own .dylib but I get the DllNotFoundException. 我正在尝试在我的Mono Mac项目中使用DLLImport以使用我自己的.dylib,但是我得到了DllNotFoundException。 I'm guessing it has something to do with my .dylib since I'm able to do this with existing .dylib files such as the libmojoshader.dylib. 我猜它与我的.dylib有关,因为我可以使用现有的.dylib文件,比如libmojoshader.dylib。

Here's how I use DLLImport 这是我如何使用DLLImport

[DllImport("libtestDylib.dylib")]
static extern int libsum(int a, int b);

I then call the libsum function in order to see if it works. 然后我调用libsum函数以查看它是否有效。

I've found that running the app through the terminal with the MONO_LOG_LEVEL="debug" MONO_LOG_MASK="dll" mono myGame.exe command is a great way to debug issues like this, however I can't get my app .exe to run. 我发现使用MONO_LOG_LEVEL =“debug”MONO_LOG_MASK =“dll”mono myGame.exe命令通过终端运行应用程序是一个很好的方法来调试这样的问题,但我无法让我的应用程序.exe运行。 I've tried using both the .exe in build folder and the one in the .app/contents/MonoBundle, I've also tried running file in .app/contents/MacOs as this is referenced in some places I've found while researching. 我已经尝试使用build文件夹中的.exe和.app / contents / MonoBundle中的.exe,我也尝试在.app / contents / MacOs中运行文件,因为这在我发现的一些地方被引用研究。

The last file throws a "File does not contain a valid CIL image." 最后一个文件抛出“文件不包含有效的CIL图像”。 and the two others "No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file". 以及另外两个“应用程序包中没有Info.plist文件或Info.plist文件中没有NSPrincipalClass”。

So, I would guess that the first step is to manage to run the app through the terminal in order to get proper debug information as for why my .dylib can't be found. 所以,我猜第一步是设法通过终端运行应用程序,以获得正确的调试信息,为什么我的.dylib无法找到。

The .dylib I made is an empty BSD C lib made in XNA4. 我制作的.dylib是一个在XNA4中制作的空BSD C lib。

Edit 编辑

I can't even seem to get the existing dylibs to work now. 我现在似乎无法让现有的dylib工作。

I found the problem by making a new Mono Mac project with a single c# file which I then compiled through the terminal and ran it with the debug command. 我通过使用单个c#文件创建一个新的Mono Mac项目来找到问题,然后我通过终端编译并使用debug命令运行它。 With the terminal feedback found out where the program was searching for the .dylib, and that the lib I made was built with the wrong architecture which was simply solved by building for 32-bit systems. 通过终端反馈找到程序搜索.dylib的位置,并且我使用错误的体系结构构建了lib,这可以通过构建32位系统来解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM