使用gcc编译时Tcl解释器未定义参考错误 [英] Tcl interpreter undefined reference error while compiling with gcc
问题描述
我是Tcl脚本的新手,并且想使用C嵌入Tcl代码.这是我从网站复制的代码,用于测试Tcl-C的工作.
I am new to Tcl scripting and would like to use C to embed Tcl codes. This is the code that I have copied from a website to test the Tcl-C working.
test.c
#include <stdio.h>
#include <tcl.h>
void main ()
{
Tcl_Interp *myinterp;
char *action = "set a [expr 5 * 8]; puts $a";
int status;
printf ("Your Program will run ... \n");
myinterp = Tcl_CreateInterp();
status = Tcl_Eval(myinterp,action);
printf ("Your Program has completed\n");
getch();
}
我正在使用MinGW编译该文件.
I am using MinGW to compile this file.
我也将 C:\ Tcl \ include 文件夹的内容复制到了 C:\ MinGW \ include 文件夹中.
I have copied the contents of the C:\Tcl\include folder into the C:\MinGW\include folder as well.
我的gcc编译命令:
gcc -o test.exe test.c
显示的错误消息:
C:\Users\user\AppData\Local\Temp\ccEHJKCb.o:tcl_connection_test.c:(.text+0x23): undefined reference to `_imp__Tcl_CreateInterp'
C:\Users\user\AppData\Local\Temp\ccEHJKCb.o:tcl_connection_test.c:(.text+0x3d): undefined reference to `_imp__Tcl_Eval'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccEHJKCb.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
我似乎在Tcl文件夹中没有任何libtcl文件.
I don't seem to have any libtcl file in the Tcl folder.
Tcl版本是ActiveTcl 8.5.15.0.297577.
The Tcl version is ActiveTcl 8.5.15.0.297577.
任何帮助将不胜感激.
推荐答案
您的示例如何嵌入Tcl已过时,并且链接行中缺少某些内容(例如, -ltcl85
).如果仅将 -ltcl85
添加到链接行,则它应该开始工作.
Your example how to embed Tcl is outdated, and you are missing certain things in your link line (-ltcl85
for example). If you simply add -ltcl85
to your link line it should start to work.
这不适用于您的情况,因为您安装了x64(64位版本)的ActiveTcl,它提供x64 dll,而不是32位dll.但是标准的mingw gcc仅适用于32位库.
It does not work in your case, because you installed the x64 (64-Bit version) of ActiveTcl, which provides x64 dlls, not 32-Bit ones. But the standard mingw gcc only works with 32-Bit libraries.
因此,要使其正常工作:
So to get this to work:
- 下载32位ActiveTcl发行版
- 使用
gcc -o test.exe test.c -Lc:/tcl/lib -Ic:/tcl/include -ltcl86
编译代码 - 调整路径,以便在PATH中找到c:\ tcl \ bin \ tcl86.dll,并确保Tcl找到了它的libdir(
set TCL_LIBRARY = c:\ tcl \ lib \ tcl8.6
) - 运行程序
但是对于更复杂的示例,您仍然需要初始化库并执行一些样板代码,因此请在调用 Tcl_CreateInterp()
,否则一些命令(例如 clock
可能无法按预期工作).
But for more complex examples, you still need to initialise the library and a do some boilerplate code, so please call Tcl_FindExecutable(argv[0]);
before the call to Tcl_CreateInterp()
otherwise a few commands (e.g. clock
might just not work as expected).
看看 http://www.tcl.tk/cgi-bin/tct/tip/66.html 了解更多详细信息.还可以查看Tcl源代码分发和tclsh shell的源代码.
Have a look at http://www.tcl.tk/cgi-bin/tct/tip/66.html for some more details. Also have a look at the Tcl source distribution and the source for the tclsh shell.
这篇关于使用gcc编译时Tcl解释器未定义参考错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!