3

如果我在 .lib(library) 文件中发现未解析的外部符号,我必须做什么。如果我在 .c 或 .cpp 中发现未解析的外部符号,我可以修复它。但是当我在 .lib(library) 文件中发现 Unresolved external symbol 时,我该如何解决这个问题?

就我而言,我发现了这样的链接器错误:

错误 1 ​​错误 LNK2019:未解析的外部符号 ___mingw_vfprintf 在函数 _fprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-global.o) 中引用 错误 2 错误 LNK2001:未解析的外部符号 ___mingw_vfprintf D:\VidPlaya_offline TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-misc.o) 错误 3 错误 LNK2001: 无法解析的外部符号 _gpg_strerror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(ecc.4)错误 LNK2019:函数 __gcry_strerror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt 中引用了无法解析的外部符号 _gpg_strerror。lib(libgcrypt_la-global.o) 错误 5 错误 LNK2001: 无法解析的外部符号 _gpg_strerror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-misc.o) 错误 6 错误 LNK2001: 无法解析的外部符号 _gpg_strerror D :\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(md.o) 错误 7 错误 LNK2001: 无法解析的外部符号 _gpg_strerror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt. o) 错误 8 错误 LNK2019:未解析的外部符号 _gpg_strsource 在函数 __gcry_strsource D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt 中引用。lib(libgcrypt_la-global.o) 错误 9 错误 LNK2019:未解析的外部符号 _gpg_err_set_errno 在函数 _do_malloc D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-global.o) 错误 10 错误 LNK2001 中引用:unresolved external symbol _gpg_err_set_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-stdmem.o) Error 11 error LNK2001: unresolved external symbol _gpg_err_set_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt. lib(libgcrypt_la-secmem.o) 错误 12 错误 LNK2001:无法解析的外部符号 _gpg_err_code_from_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-module.o) Error 13 error LNK2019: unresolved external symbol _gpg_err_code_from_errno referenced in function _gpg_err_make_from_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib (libgcrypt_la-global.o) 错误 14 错误 LNK2001: 无法解析的外部符号 _gpg_err_code_from_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-sexp.o) 错误 15 错误 LNK2001: 无法解析的外部符号 r_pger_from_d: \VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(md.o) 错误 16 错误 LNK2001:unresolved external symbol _gpg_err_code_from_errno D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(primegen.o) Error 17 error LNK2019: unresolved external symbol ___mingw_vsprintf referenced in function _sprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore \libgcrypt.lib(libgcrypt_la-sexp.o) Error 18 error LNK2001: unresolved external symbol ___mingw_vsprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(ac.o) Error 19 error LNK2001: unresolved external symbol _gpg_errsyserror_code D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(primegen.o) 错误 20 错误 LNK2019:unresolved external symbol _gpg_err_code_from_syserror referenced in function _progress D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(dsa.o) Error 21 error LNK2001: unresolved external symbol _gpg_err_code_from_syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore \libgcrypt.lib(ecc.o) Error 22 error LNK2001: unresolved external symbol _gpg_err_code_from_syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(random-fips.o) Error 23 error LNK2001: unresolved external symbol_gpgercodefrom__syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(mpicoder.o) Error 24 error LNK2001: unresolved external symbol _gpg_err_code_from_syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(cipher.o) Error 25 error LNK2001: unresolved external symbol _gpg_err_code_from_syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\ vlcwin\libvlccore\libgcrypt.lib(pubkey.o) Error 26 error LNK2001: unresolved external symbol _gpg_err_code_from_syserror D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(kdf.o) Error 27 error LNK2019: unresolved external symbol _snprintf 在函数 __gcry_pk_get_keygrip D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(pubkey.o) 错误 28 错误 LNK2001: 无法解析的外部符号 _snprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(md.o) 错误 29 错误 LNK2001: 无法解析的外部符号 _snprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\TryingToIncludeUpdateFacility\TryingToIncludeUpdateFacility\ vlcwin\libvlccore\libgcrypt.lib(ecc.o) Error 30 error LNK2001: unresolved external symbol _snprintf D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(rndw32.o) Error 31 error LNK2019: unresolved external symbol在函数 _init_pool D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(libgcrypt_la-secmem.o) 中引用的 _getpagesize 错误 32 错误 LNK2019:在函数 _x931_get_dt D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\libvlccore\libgcrypt.lib(random-fips.o) 中引用的未解析的外部符号 _gettimeofday (random-fips.o) 错误 33 错误 LNK2001:未解析的外部符号 _gettimeofday D:\VidPlaya_offline\Vvlcplay_PluginUpdateFbeddedEmbeddedity\Vvlcplayid \libvlccore\libgcrypt.lib(random-csprng.o) Error 34 error LNK1120: 10 unresolved externals D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\Release\libvlccore.dll Error 89 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall UpdateDialog::metaObject(void)const " (?metaObject@UpdateDialog@@UBEPBUQMetaObject@@XZ) D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\lib_plugin\help.obj 错误 90 错误 LNK2001:无法解析的外部符号“public:virtual void * __thiscall UpdateDialog::qt_metacast(char const *)”(?qt_metacast@UpdateDialog@@UAEPAXPBD@Z) D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\lib_plugin\help.obj 错误 91 错误 LNK2001:无法解析的外部符号“public:virtual int __thiscall UpdateDialog::qt_metacall(enum QMetaObject::Call,int,void * *)”(? qt_metacall@UpdateDialog@@UAEHW4Call@QMetaObject@@HPAPAX@Z) D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\lib_plugin\help.obj Error 92 error LNK1120: 3 unresolved externals D:\VidPlaya_offline\TryingToIncludeUpdateFacility\Vidplaya_Plugin_EmbeddedUpdate\vlcwin\Release\plugins\lib_plugin.dll

有关此的任何建议都会有所帮助。

4

2 回答 2

3

好吧,基本上你必须找到具有该符号的库 - .lib 或 .a(取决于平台)文件。静态库在链接到可执行文件或共享库之前不会解析它们的符号,因此您可能有一个静态库没有解析其所有符号。您可以使用第 1 点中提到的工具验证这一点 - 当您转储符号时,未解析的符号U前面将有一个字母。当您将它们链接到您的应用程序时,链接器必须解析所有符号,如果缺少某些东西,您会得到未解决的引用错误。你基本上有两个选择:

1)使用符号转储实用程序,如nm(Windows 上的 Linux 和 MinGW)或dumpbin(Windows 上的 Visual Studio)和符号的 grep(如果您有一个充满库的目录,您可以为每个文件创建一个脚本),并且然后,当您知道正确的库文件将您的代码链接到它时(再次取决于-l<library name>Linux 和 MinGW windows 的平台切换,#pragma comment(lib, "<library name>")通过 Visual Studio 中的属性页添加或指定库。

2)如果您有所有库的源代码,您可以对函数的定义进行纯文本搜索,然后链接到具有源代码的库。

3) 即使您已经链接到正确的库但 C 和 C++ 代码混合在一起,这些问题也可能出现。具有 C 接口的库应将其头文件包含在一个extern "C"块中,以便在只有具有 C 名称的函数可用时,链接器不会尝试查找具有 C++ 名称的函数。对于 FFmpeg 和其他大型开源项目的初学者来说,这是一个常见的问题。

更新

至于最初的问题__mingw_vfprinf- 您将使用 MinGW 编译的代码与 Visual Studio 链接起来有点奇怪,我想说您最好也将 MinGW 用于您的项目,但正如在类似的建议中所建议的那样主题这可能是由于缺少libmingwex.a. 如果您有 MinGW 工具链,请找到文件所在的位置,通过 Visual Studio 属性页将该目录添加到链接器搜索目录,并libmingwex.a通过 Visual Studio 属性页或通过上述 pragma 作为链接器输入添加到您的项目。如果您没有 MinGW 工具链,那么您应该下载它,但您需要获得正确的平台 - 但是我想既然您将库放在某个地方,您就知道它是 32 位还是 64 位。

更新 2

这是 MinGW 包管理器的示例屏幕截图,显示了哪个包包含该库:

显示 libmingwex.a 的 MinGW 包管理器

于 2014-10-21T14:53:09.770 回答
1

我对其他运行时库实现的经验使我假设各种printf变体是通过调用较低级别的vprintf表单来实现的。 fprintf被放入 thay .o 文件中(为什么?这本身不是 RTL 函数吗?)它需要那个辅助函数。从名称装饰中,我希望可以在 mingw 系统库中找到它。我相信 printf 函数位于您需要链接的补充库中,因为它比 msvcrt.dll 中的函数得到了增强。

所以,寻找那个。还要检查您的版本,因为该库可能是针对与您现在使用的版本不同的版本构建的,并且这些细节已经改变。

于 2014-10-21T14:38:24.053 回答