目标:
获取包装器dll,以便在Windows中的统一项目中使用pocketsphinx。
问题:
在运行测试程序时,我会得到一个恼人的System.DllNotFoundException
,即使.so文件与mono程序位于同一个目录中。
设置和尝试操作:
首先,我用的是Cygwin。我可以建造所有的东西,斯芬克斯基地和口袋狮身人面像没有问题。然后,我进入了swig/csharp目录,并尝试了make。它确实创建了一个.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:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll': 'The system cannot find the file specified.
一遍又一遍。
任何帮助都将不胜感激。同样,我需要一个用于libpocketsphinx.so x86_64的窗口,以便与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);
发布于 2017-08-06 06:10:27
我怀疑Cygwin DLL是否与Mono/Unity兼容。您需要在中创建DLL,然后它才能工作。
发布于 2017-08-06 05:28:52
为什么要用mono来测试so文件,而实际上它是在Unity中使用的?
'C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\libpocketsphinxwrap.so.dll'::DllImport错误加载库系统找不到指定的文件。
如果文件libpocketsphinxwrap.so
确实存在于C:\Users\fgera\Development\Tools\CMUSphinx\pocketsphinx\swig\csharp\
中,请尝试将libpocketsphinxwrap.so
重命名为libpocketsphinxwrap.so.dll
,以便mono可以找到它。
另见单点调用:库名和DllNotfoundException。
您可以尝试从它是非正式支持的。开始使用Visual构建袖珍狮身人面像。
顺便说一句,我宁愿自己编写C#包装器,而不是使用SWIG,因为P/Invoke中有许多陷阱,而且我认为SWIG不能处理所有这些陷阱。
https://stackoverflow.com/questions/45528592
复制相似问题