目标:System.DllNotFoundException在pocketsphinx痛饮统一窗口建设
获取一个包装DLL在Windows中的一个统一项目中使用pocketsphinx。
问题:
当运行测试程序,我得到一个恼人的System.DllNotFoundException
即使.so文件是在同一目录下单程序。
安装和尝试的操作:
对于初学者,我使用的是Cygwin。我能够建立绝对的一切,sphinxbase和pocketsphinx没有问题。然后我进入了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 [email protected]
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: DllImport error loading library 'C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll': 'The system cannot find the file specified.
很多次一遍又一遍。
任何帮助将不胜感激。同样,我需要在Unity中使用libpocketsphinx.so x86_64 for windows来与C#文件进行交互。
谢谢。
---编辑 - 添加相关代码片段。 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);
你最好通过构建一个真正的Unity项目而不是使用mono来测试它。他们是不同的。 – zwcloud
@zwcloud我在Unity中遇到同样的错误。 Unity也使用mono。它应该在两个方面工作。 – Fer
再次..请编辑您的问题并发布test.cs的内容:让我们看看如何使用属性“DllImport”定义extern方法。 – zwcloud