【发布时间】:2011-09-21 09:48:17
【问题描述】:
我一直在关注使用 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
据我所知,我并没有偏离教程。谁能告诉我我是怎么得到这个错误的,更重要的是如何摆脱它?
提前致谢!
【问题讨论】:
-
Tcl 有自己的优秀 C 代码接口。我建议只研究它,而不是在 SWIG 上浪费时间。
-
我会,但我做这个教程的原因是我以后可以在我的 TCL 脚本中使用已经提供的 SWIG 接口和 C 文件。恐怕它不适用于在 TCL 中使用 C 代码的其他方式。
-
执行 'file test.so' 和 'nm -AC test.so' 并显示输出