使用 Swig 将 C 和 TCL 结合起来
我一直在遵循使用 Swig 将 C 与 TCL 结合起来的教程。该教程似乎工作正常,但最后我遇到了一个无法解决的错误。情况如下:
我遵循的教程是: http://www.swig.org/tutorial.html。
我有一个名为 test.c: 的文件
char *HelloWorld()
{
return "hello world";
}
和另一个名为 test.i: 的
%module test
%{
/* Put header files here or function declarations like below */
extern char *HelloWorld();
%}
extern char *HelloWorld();
文件,然后我使用以下命令行参数来准备正确的文件:
gcc -c test.c -o test.o
swig -tcl test.i
gcc -c test_wrap.c -o test_wrap.o
gcc -dynamiclib -framework Tcl test.o test_wrap.o -o test.so
最后我尝试使用以下方式加载它:
tclsh
% load test.so test
这是我收到以下错误的地方:
dlsym(0x100600090, Test_Unload): symbol not founddlsym(0x100600090, Test_SafeUnload): symbol not found
据我所知,我并没有偏离教程。谁能告诉我我是如何得到这个错误的,更重要的是如何摆脱它?
提前致谢!
I have been following a tutorial to combine C with TCL using Swig. The tutorial seemed to be properly working but at the end I ran into an error that I cannot solve. The situation is as follows:
The tutorial I was following is:
http://www.swig.org/tutorial.html.
I have a file named test.c:
char *HelloWorld()
{
return "hello world";
}
and another named test.i:
%module test
%{
/* Put header files here or function declarations like below */
extern char *HelloWorld();
%}
extern char *HelloWorld();
I then used the following command line arguments to ready the correct files:
gcc -c test.c -o test.o
swig -tcl test.i
gcc -c test_wrap.c -o test_wrap.o
gcc -dynamiclib -framework Tcl test.o test_wrap.o -o test.so
And finally I tried to load it using:
tclsh
% load test.so test
This is the point where I received the following error:
dlsym(0x100600090, Test_Unload): symbol not founddlsym(0x100600090, Test_SafeUnload): symbol not found
As far as I know I did not stray from the tutorial. Can anyone tell me how it is that I got this error and more importantly how to get rid of it?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些错误消息是否会阻止
加载
工作?他们不应该;他们报告说不存在支持卸载扩展的低级 API,但这没关系(很多扩展无法卸载;编写支持它的代码很棘手)。您没有具体提及您正在使用哪个版本的 Tcl — 但它必须至少为 8.5 才能首先搜索这些符号 — 因此很难猜测确切的根本问题是什么。 (该消息不应被报告。)我建议提交 错误报告对此; 确保您在报告中包含所有准确的版本。
Are those error messages stopping the
load
from working? They shouldn't; they're reporting that the low-level API for supporting unloading of the extension isn't present, but that's OK (lots of extensions can't be unloaded; it's tricky to write code that supports it).You don't mention exactly which version of Tcl you are using — but it must be at least 8.5 for those symbols to be even searched for in the first place — so it is a little hard to guess what the exact underlying issue is. (The message should simply not be reported.) I advise filing a bug report on this; make sure you include all exact versions in your report.
我已经很长时间没有使用 SWIG 了,所以我不确定它是否能让您充分控制它生成的代码,以便您能够应用此修复程序。掩盖这个细节,我可以通过以下内容重现(并修复)该问题:
在“ext.c”中:
构建,运行 tclsh,加载扩展:
库加载代码内部的某些内容将该错误消息放入解释器结果中。要停止显示消息,请设置或重置结果,以便 _Init() 函数以以下一项或多项结束:
init block swig 的功能可能在正确的位置插入代码来实现相同的效果:
It's a long time since I used SWIG, so I'm not sure whether it gives you sufficient control over the code it generates for you to be able to apply this fix. Glossing over that detail, I can reproduce (and fix) the issue with the following:
In 'ext.c':
Build, run tclsh, load extension:
Something internal to the library loading code is putting that error message into the interpreters result. To stop the message ever surfacing, set or reset the result so that the _Init() function ends with one or other of:
The init block feature of swig might insert code in the right place to achieve the same thing: