【问题标题】:TCL: linking with static library in windowsTCL:在windows中与静态库链接
【发布时间】:2020-10-21 17:58:39
【问题描述】:

我已经从here 下载了 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

在输出中,我可以得到tcl87s.lib - tcldds14s.lib - tclreg13s.lib

现在我正在尝试构建我的 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;
}

因为我需要在 Windows 中构建它,所以我在 Visual Studio 命令提示符中编译这段代码:

cl -I"D:\path\to\tcl\include" myCode.c D:\path\to\tcl87s.lib

但不幸的是,我总是遇到这些错误:

error LNK2019: unresolved external symbol __imp__Tcl_Alloc referenced in function ...
error ....................................__imp__Tcl_Free ..................
error ....................................__imp__Tcl_CreateInterp ..................

............以及其他 TCL 函数的更多错误......

如果我将 TCL 构建为动态库,则没有错误,我可以编译我的 C 代码。有谁知道可能是什么问题

【问题讨论】:

  • 唉,您需要在 Windows 上构建的人的建议。那是我不用于开发的平台;我没有用于它的工具链(更不用说你拥有的工具链了),而且我对项目在那里的工作方式几乎没有经验。 但是, 该消息似乎表明函数未绑定到其实现,并表明缺少库。 Tcl 库的绑定工作方式肯定会根据链接选项而有所不同;在静态链接中,它应该直接指向命名函数,而不是它们的导入存根。
  • @DonalFellows .. 感谢您的回复.. 原来我在编译 C 代码时必须使用标志 -DSTATIC_BUILD。

标签: c compilation tcl static-libraries


【解决方案1】:

原来我在编译我的 C 代码时必须使用标志 -DSTATIC_BUILD。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多