c++ - LNK2019 : Unresolved external symbol __imp__ in the . obj 文件第 1 行

标签 c++ linker-errors

我不确定出了什么问题。我将描述问题,然后是我对发生的情况的理解。这是一个简单的代码:

#include <iostream>
#include <stdio.h>
#include "stdafx.h"
#include <iViewNG-Core.h>

int main(int argc, char ** args) {

    iViewVersion version;
    iViewRC rc = iView_GetLibraryVersion(&version);

    if (RC_NO_ERROR != rc)
        printf("ERROR returned by iView_GetLibraryVersion(): %d\n", rc);

    printf("The version of the libiViewNG is: %u.%u.%u.%u\n", version.major, version.minor, version.patch, version.build);

    return 0;
}

错误描述:

Error LNK2019 unresolved external symbol __imp__iView_GetLibraryVersion@4 referenced in function _main SMI_TrialTests c:\Users\Rakshit\documents\visual studio 2015\Projects\SMI_TrialTests\SMI_TrialTests\SMI_TrialTests.obj

我确认代码确实正在读取 iViewNG-Core.h,因为自动填充允许我使用文件中声明的函数。我通过在适当的 VC++ 目录中正确添加 lib 和 include 目录来做到这一点。由于这是链接器问题,我哪里出错了?

我是 C++ 新手,我知道有大量重复的 LNK2019 问题,但似乎没有一个能解决我的问题。

链接器输出:

/OUT:"c:\users\rakshit\documents\visual studio 2015\Projects\SMI_TrialTests\Debug\SMI_TrialTests.exe" /MANIFEST /NXCOMPAT /PDB:"c:\users\rakshit\documents\visual studio 2015\Projects\SMI_TrialTests\Debug\SMI_TrialTests.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"c:\users\rakshit\documents\visual studio 2015\Projects\SMI_TrialTests\Debug\SMI_TrialTests.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\SMI_TrialTests.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /VERBOSE /LIBPATH:"C:\iView NG SDK\lib\lib-Windows7-32" /TLBID:1

最佳答案

检查符号__imp__iView_GetLibraryVersion@4,它可以分为两个 block :

  • __imp_:这意味着__declspec(dllimport)
  • _iView_GetLibraryVersion@4:这是实际的符号,被破坏为 C(或 extern "C")__stdcall 符号,其中参数总共4个字节大小。

考虑到这一点,并根据您的代码,导致问题的函数可能是:

extern "C" __declspec(dllimport) iViewRC __stdcall iView_GetLibraryVersion(iViewVersion*);

我建议检查包含此函数的 DLL 的 LIB 文件是否被传递给 cllink(在前一种情况下,cl 会将其传递给 link)。

关于c++ - LNK2019 : Unresolved external symbol __imp__ in the . obj 文件第 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39499394/

相关文章:

c++ - 在 Qt4 UI 中将用户输入的数据写入文件

c++ - STLR(B) 是否在 ARM64 上提供顺序一致性?

ios - 如何解决链接器命令错误?

c - 使用 LIBSVM 将 svm.cpp 文件与我的 C 程序链接时出错

c++ - IID_MediaControl 未声明的标识符

c++ - 与 AWS SDK 的链接问题

c++ - 默认的构造函数和析构函数是内联的吗?

c++ - 在 Windows 中检索全局钩子(Hook)链

c++ - expat 对 `XML_SetElementHandler' 的 undefined reference

c++ - 在 Fedora 20 上构建 Blender,OSL 编译失败