简体   繁体   English

TCL:与 Windows 中的静态库链接

[英]TCL: linking with static library in windows

I have downloaded TCL source from here and I can compile it to generate static library in Windows7 using the following command我已经从这里下载了 TCL 源代码,我可以使用以下命令编译它以在 Windows7 中生成静态库

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在输出中,我可以得到tcl87s.lib - tcldds14s.lib - tclreg13s.lib

Now I am trying to build my C code (that has TCL embedded):现在我正在尝试构建我的 C 代码(嵌入了 TCL):

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:因为我需要在 Windows 中构建它,所以我在 Visual Studio 命令提示符中编译此代码:

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....... ......以及其他 TCL 功能的更多错误......

If I built TCL as a dymanic library, no errors and I can compile my C code.如果我将 TCL 构建为动态库,则没有错误,我可以编译我的 C 代码。 Does anyone know what could be the problem有谁知道可能是什么问题

事实证明,我必须在编译 C 代码时使用标志 -DSTATIC_BUILD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM