【发布时间】:2019-02-28 15:49:47
【问题描述】:
我有一个包含 tcl.h 库的 cpp 代码。我正在尝试使用 gcc 编译器对其进行编译。但我收到以下错误:
gcc -o top.o -std=c99 top.c
top.c:12: warning: return type defaults to 'int'
/tmp/ccDOTTZQ.o: In function `main':
top.c:(.text+0xa): undefined reference to `Tcl_CreateInterp'
top.c:(.text+0x1f): undefined reference to `Tcl_EvalFile'
top.c:(.text+0x3d): undefined reference to `Tcl_GetVar2Ex'
top.c:(.text+0x75): undefined reference to `Tcl_ListObjGetElements'
top.c:(.text+0xb1): undefined reference to `Tcl_GetString'
top.c:(.text+0xcc): undefined reference to `Tcl_GetInt'
collect2: ld returned 1 exit status
它无法找到 Cpp-tcl API。请帮我解决这个问题。
【问题讨论】:
-
您必须链接库。像 libtcl.so 之类的东西
-
我应该使用哪个选项来链接它们以及该对象文件在哪里可用?
-
我不知道目标文件在哪里。但如果它们位于标准位置,请将
-ltcl添加到 g++ 编译中。如果它们不在标准位置,请添加-L/path/to/libctl.so。 注意: -l 选项中,lib 前缀和.so 后缀不应传递 -
我尝试提供 -ltcl 选项。有效。谢谢。
-
我还需要从 tcl 脚本中读取本地声明的变量(在 TCL 脚本中)值,还需要从我的 cpp 代码中将值传递给 TCL 脚本。如何做到这一点?