I have downloaded TCL source from here and I can compile it to generate static library in Windows7 using the following command
nmake -f makefile.vc OPTS=static INSTALLDIR=path_to_your_install_dir
nmake -f makefile.vc install OPTS=static INSTALLDIR=path_to_your_install_dir
In the output, I can get tcl87s.lib - tcldds14s.lib - tclreg13s.lib
Now I am trying to build my C code (that has TCL embedded):
static const char *user_script = "puts \"Hello World ........\"\n";
int my_cmd(Tcl_Interp *interp, const char *arg_str, ...){
char *cmd_str = Tcl_Alloc(256);
va_list ap;
int result;
va_start(ap,arg_str);
vsprintf(cmd_str, arg_str, ap);
result = Tcl_Eval(interp,cmd_str);
Tcl_Free(cmd_str);
return result;
}
int main (int argc ,char *argv[])
{
Tcl_FindExecutable(argv[0]);
Tcl_Interp *myinterp;
printf ("C: Starting ... \n");
myinterp = Tcl_CreateInterp();
if (Tcl_Init(myinterp) != TCL_OK) {
printf("Error: %s\n",Tcl_GetStringResult(myinterp));
return TCL_ERROR;
}
if (my_cmd(myinterp, user_script) != TCL_OK) {
printf("Error: %s\n",Tcl_GetStringResult(myinterp));
return TCL_ERROR;
}
Tcl_DeleteInterp(myinterp);
Tcl_Finalize();
return TCL_OK;
}
Because I need to build it in Windows, I am compiling this code in Visual Studio Command Prompt:
cl -I"D:\path\to\tcl\include" myCode.c D:\path\to\tcl87s.lib
But unfortunately, I get always these errors:
error LNK2019: unresolved external symbol __imp__Tcl_Alloc referenced in function ...
error ....................................__imp__Tcl_Free ..................
error ....................................__imp__Tcl_CreateInterp ..................
.........and more errors for other TCL functions.......
If I built TCL as a dymanic library, no errors and I can compile my C code. Does anyone know what could be the problem
事实证明,我必须在编译 C 代码时使用标志 -DSTATIC_BUILD。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.