链接器在构建 GTSAM 样本时找不到 __imp_clock 和 __imp_time64

问题描述

我在 Windows 中构建 GTSAm,现在我正在尝试用它构建示例应用程序。

示例应用程序非常简单(它是 GTSAM 的一部分),但是当我运行它时,我收到此链接错误

Severity    Code    Description Project File    Line    Suppression State Error LNK2019 unresolved external symbol __imp_clock referenced in function gk_cpuSeconds example D:\MyData\SourceCode\gtsam_win\cmake\example_cmake_find_gtsam\build\metis-gtsamDebug.lib(timers.obj)    

Severity    Code    Description Project File    Line    Suppression State Error LNK2019 unresolved external symbol __imp__time64 referenced in function time    example D:\MyData\SourceCode\gtsam_win\cmake\example_cmake_find_gtsam\build\metis-gtsamDebug.lib(timers.obj)    1   

搜索显示这两个函数是 MSVC 库的一部分,它们应该链接到系统。

我该如何解决这个问题?

问题似乎是库构建和应用程序构建期间的设置不匹配,但我找不到任何不同的链接器设置。在哪里寻找任何此类差异?

解决方法

来自链接库的未解析外部运行时库符号中的

__imp_ 前缀表示该库是使用 DLL 运行时构建的(/MD 中的 C++ -> Code Generation -> Runtime Library)。

如果您使用静态运行时 (/MT) 构建应用程序,则来自 DLL 运行时的符号将无法解析。所有编译单元的运行时设置应该相同。