System.DllNotFoundException in pocketsphinx swig Unity windo



>目标:

获取包装器 dll 以在 Windows 中的 Unity 项目中使用 pocketsphinx。

问题:

运行测试程序时,即使 .so 文件与 mono 程序位于同一目录中,我也会收到一个烦人System.DllNotFoundException

设置和尝试的操作:

首先,我正在使用Cygwin。我能够建造绝对的一切,狮身人面像和口袋狮身人面像没有问题。然后我进入了swig/csharp目录并尝试制作。它确实会创建一个 .so 文件。我正在使用默认的Makefile并在cygwin中制作。规则 1-3 运行良好,构建、链接和一切。pocketsphinx_continuous测试也是如此。

pocketsphinx.c: ../pocketsphinx.i
mkdir -p gen
swig -I.. -I../../../sphinxbase/swig -I../include -I../../sphinxbase/include 
-csharp 
-dllimport "libpocketsphinxwrap.so" 
-namespace "Pocketsphinx" -o sphinxbase.c 
-outdir gen ../../../sphinxbase/swig/sphinxbase.i
swig -I.. -I../../../sphinxbase/swig -I../include -I../../sphinxbase/include 
-csharp 
-dllimport "libpocketsphinxwrap.so" 
-namespace "Pocketsphinx" -o pocketsphinx.c 
-outdir gen ../pocketsphinx.i
libpocketsphinxwrap.so: pocketsphinx.c
gcc -fPIC pocketsphinx.c sphinxbase.c `pkg-config --libs --cflags pocketsphinx` -shared -o $@
test.exe: libpocketsphinxwrap.so
mcs test.cs gen/*.cs
run: test.exe
MONO_LOG_LEVEL=debug mono test.exe
clean:
rm -rf gen
rm -f libpocketsphinxwrap.so
rm -f pocketsphinx.c
rm -f sphinxbase.c
rm -f test.exe
.PHONY: run clean

尝试mono test.exe时 - 发生以下情况:

Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Pocketsphinx.PocketSphinxPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: libpocketsphinxwrap.so

.so与 test.exe 文件位于同一目录中,并且肯定会被查看,因为当使用MONO_LOG_LEVEL=debug运行 mono 时,输出为:

Mono: DllImport error loading library 'C:UsersfgeraDevelopmentToolsCMUSphinxpocketsphinxswigcsharplibpocketsphinxwrap.so.dll': 'The system cannot find the file specified.

一遍又一遍。

任何帮助将不胜感激。同样,我需要 Unity 中的窗口与 C# 文件互操作 libpocketsphinx.so x86_64。

谢谢。

---编辑 - 添加了相关代码段。 test.cs只是从包装器数据结构调用此方法。这些文件都是由SWIG生成的。

[global::System.Runtime.InteropServices.DllImport("libpocketsphinxwrap.so", EntryPoint="CSharp_Pocketsphinx_Decoder_GetConfig")]
public static extern global::System.IntPtr Decoder_GetConfig(global::System.Runtime.InteropServices.HandleRef jarg1);

我怀疑Cygwin DLL是否与Mono/Unity兼容。你需要在Visual Studio中创建DLL,然后它就可以工作了。

为什么你用单声道测试so文件,而它实际上是在Unity中使用的?

Mono: DllImport 加载库时出错 'C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll':"系统找不到指定的文件。

如果文件libpocketsphinxwrap.so确实存在于C:UsersfgeraDevelopmentToolsCMUSphinxpocketsphinxswigcsharp中,请尝试将libpocketsphinxwrap.so重命名为libpocketsphinxwrap.so.dll以便mono可以找到它。

另请参阅 mono pinvoke: Library names 和 DllNotfoundException。


您可以尝试使用Visual Studio构建pocketsphinx,因为它是官方支持的。

顺便说一句,我宁愿自己编写 C# 包装器而不是使用 SWIG,因为 P/Invoke 中有很多陷阱,我认为 SWIG 无法处理所有这些陷阱。

最新更新