使用正在调用TCL脚本的CPP代码的GCC编译

Compiling using gcc of a Cpp code which is calling a TCL script

本文关键字:CPP 代码 GCC 编译 脚本 TCL 调用      更新时间:2023-10-16

i有一个CPP代码,其中包括TCL.H库。我正在尝试使用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。请帮助我。

您的代码没有链接到TCL库,因此显然找不到这些功能的实现。(在C和C 中,函数的实现的链接与使用这些函数的声明的使用是一个单独的阶段,这是标题文件提供的。)

除了您实际上将GCC误认为是错误的。您需要使用两个步骤,首先使用-c compile 源代码到对象文件:

gcc -c -o top.o -std=c99 top.c 

然后像这样链接结果并制作一个可执行文件:

gcc -o top.exe -std=c99 top.o -ltcl

在第一个情况下,您可能需要另外指定适当的-I选项以找到Include文件(如果它们不在标准位置)。使用第二个,您可能需要指定一个适当的-L选项以找到库文件(libtcl.so)。根据系统的不同,您可能还需要指定某些版本号(例如-ltcl86-ltcl8.6而不是-ltcl)。这些都是取决于您的构建系统配置的所有选项,因此它们很难在此处准确预测。