当前位置: 首页 > 编程语言 > C#

swig+mono-C#exampleerrornotfoundlibraryshare

时间:2023-04-11 11:25:58 C#

swig+mono:C#exampleerrornotfoundlibrary我在MacOSX10.6.42.8上使用swig2.0.1+mono2.6/。整体构建很好,C#示例的构建也是如此。问题是当我运行示例(monorunme.exe)时,我总是会收到以下错误。未处理的异常:System.TypeInitializationException:类初始程序抛出examplePINVOKE抛出异常--->System.TypeInitializationException:SWIGExceptionHelper的类初始进程抛出异常--->System.DllNotFoundException:to-wnperativemanaged)examplePINVOKE/SWIGExceptionHelper:SWIGRegisterExceptionCallbacks_example(examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGException上的examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate)Helper..cctor()[0x00000]in:0---内部异常堆栈跟踪结束---在examplePINVOKE..cctor()[0x00000]:0---内部异常堆栈跟踪结束---inexample.gcd(Int32x,Int32y)[0x00000]in:0atrunme.Main()[0x00000]in:0貌似没有找到示例库,但是生成的库是libexample.so这个是生成的libexample.so库的源码doubleFoo=3.0;intgcd(intx,inty){...}这是使用libexample.so的C#源代码。使用系统;publicclassrunme{staticvoidMain(){intx=42;整数y=105;intg=example.gcd(x,y);...}}这是使用SWIG生成的包装函数。/*------------------------------------------------------------------------*此文件由SWIG(http://www.swig.org)自动生成。*版本2.0.1**除非您知道自己在做什么,否则不要更改此文件——改为修改*SWIG接口文件。*------------------------------------------------------------------------*/使用系统;使用System.Runtime.InteropServices;公共类示例{publicstaticintgcd(intx,inty){intret=examplePINVOKE.gcd(x,y);返还;}publicstaticdoubleFoo{set{examplePINVOKE.Foo_set(value);}get{doubleret=examplePINVOKE.Foo_get();返还;gcc-cexample.cexample_wrap.ccc-bundle-undefinedsuppress-flat_namespaceexample.oexample_wrap.o-olibexample.somake-f../../MakefileCSHARPSRCS='*。cs'CSHARPFLAGS='-nologo-out:runme.exe'csharp_compilegmcs-nologo-out:runme.exe*.cs可能有什么问题?应该怎么做才能让mono知道libexample.so?我可以使用“swig-csharp-dllimport”libexample.so“example.i”,但我得到了相同的结果。我附上了examplePINVOKE.cs。如本文所述,我运行了“MONO_LOG_LEVEL=debugmonorunme.exe”。该消息表示单声道无法找到./libexample.so,即使该文件已退出。单声道:DllImport加载的库:'。/libexample.so'。Mono:DllImport加载库“(null)”时出错。解决方案我可以更改swig/Examples中的Makefile来解决这个问题。CFLAGS=-archi386这可能是库被编译为64位造成的。“(null)”表示Mono无法获取此错误的错误消息。您可以通过设置适当的编译标志来解决此问题。例如:./configureCFLAGS="-O-archi386"CXXFLAGS="-O-archi386"LDFLAGS="-archi386"--disable-dependency-tracking您还可以使用Mono的实验性64位支持来解决这个问题,但我从来没有这样做过,所以我不确定。System.DllNotFoundException:示例看起来它找不到您的非托管dll:“示例”。您可以在接口文件中指定pinvoke签名的目标DLL。您还应该确保该文件位于动态链接器搜索路径中,即在MacOS上:而不是.so文件。以上就是C#学习教程:swig+mono:TheC#example错误分享的库没有找到。代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: