未解析的外部符号 __vsnprintf ....(在 dxerr.lib 中)?
Unresolved external symbol __vsnprintf .... (in dxerr.lib)?
我是 运行 windows 7 和 visual studio 社区 2015 RC 上的 DirectX 11 应用程序。我仍在使用 DX SDK 中的函数。它在 VS2013 上运行良好,但当我切换时,我只收到以下错误:
Error LNK2019 unresolved external symbol __vsnprintf referenced in function "long __stdcall StringVPrintfWorkerA(char *,unsigned int,unsigned int *,char const *,char *)" (?StringVPrintfWorkerA@@YGJPADIPAIPBD0@Z) Ancora D:\Moody\Moody\Projects\Projects\Ancora\Ancora\dxerr.lib(dxerra.obj) 1
我只使用 dxerr 库中的 DXGetErrorDescriptionA 函数,当我注释掉它时,程序编译正常。我不知道出了什么问题,但它不能来自 DX SDK,否则其他功能会失败吗?
您正在使用的 DirectX 库是使用比您正在使用的旧版本 Visual Studio 编译的。 Microsoft 有时会更改其 C 运行时,从而在使用不同版本编译的库之间造成不兼容。 __vsnprintf
是旧版本 C 运行时的内部符号,在 2015 RC 版本中不存在。
不幸的是,dxerr.lib(连同 d3dx11.lib)现在已经 deprecated. You have two options - you can switch back to VS2013 or you can stop using functionality from dxerr.lib. The latter is probably better, because you can duplicate its functionality by using FormatMessage(链接文章中有更多信息)。
HACKY 但你可以修补 dxerr.lib。
将 __vsnprintf 替换为 _vsnprintf(末尾为空以说明开头删除的下划线)
您可以添加
,而不是手动破解 dxerr.lib
#include <Windows.h>
#include <stdio.h>
int (WINAPIV * __vsnprintf)(char *, size_t, const char*, va_list) = _vsnprintf;
代码中的某处
遗留的 DirectX SDK 很旧,DXSDK 中的 dxerr.lib
与您遇到的 VS 2015 的 C 运行时不兼容。
一般来说,其中包含代码的静态库不能很好地与不同版本的编译器混合使用。旧版 DirectX SDK 中的大多数 .libs 都适用于 VS 2015,因为它们是 dll 或所有数据库的导入库,因此根本不包含任何代码。 DXSDK 自 VS 2010 以来未更新。
Aside: The VS team has made a heroic effort to keep the Visual C/C++ Runtime link compatible between VS 2015 Update 3, VS 2017, and VS 2019 per Microsoft Docs. This is not the normal pattern.
Be sure to read the instructions on Microsoft Docs on the proper way to mix the legacy DirectX SDK with the Windows 8.x SDK used by VS 2015. You are presumably using something else from the legacy DirectX SDK in this project besides dxerr.
我已经实现了一个 DXERR 版本,您可以在项目中从源代码构建它,以消除对旧版 DirectX SDK 的依赖。有关详细信息,请参阅 this post。也就是说,我故意只支持 Unicode(W 版本)。您可以很容易地弄清楚如何制作 ANSI(A 版本),但最好更新您的应用程序以使用 Unicode。
参见Where is the DirectX SDK (2021 Edition)? and DXUT for Direct3D 11。
更新: 正如在另一个答案中指出的那样 linking with legacy_stdio_definitions.lib
应该使旧的遗留 DirectX SDK 版本 dxerr.lib
link 再次使用 VS 2015/2017。也就是说,您应该尽可能地消除对遗留 DirectX SDK 的依赖,并且 DXERR 很容易被您自己的模块替换。参见 Living without D3DX。
我在使用 DXGetErrorMessage()
和 Dx9
时遇到了同样的问题,发现 MS 提供了一个额外的库来包含在 Additional Dependencies
属性页面中以解决这个问题。库名称是:legacy_stdio_definitions.lib
添加这个解决了我的问题。
您可以将平台工具集从 Visual Studio 2015 更改为 Visual Studio 2013,然后编译。
平台工具集位于项目属性的常规选项卡上。
只需添加
#pragma comment(lib, "legacy_stdio_definitions.lib")
我是 运行 windows 7 和 visual studio 社区 2015 RC 上的 DirectX 11 应用程序。我仍在使用 DX SDK 中的函数。它在 VS2013 上运行良好,但当我切换时,我只收到以下错误:
Error LNK2019 unresolved external symbol __vsnprintf referenced in function "long __stdcall StringVPrintfWorkerA(char *,unsigned int,unsigned int *,char const *,char *)" (?StringVPrintfWorkerA@@YGJPADIPAIPBD0@Z) Ancora D:\Moody\Moody\Projects\Projects\Ancora\Ancora\dxerr.lib(dxerra.obj) 1
我只使用 dxerr 库中的 DXGetErrorDescriptionA 函数,当我注释掉它时,程序编译正常。我不知道出了什么问题,但它不能来自 DX SDK,否则其他功能会失败吗?
您正在使用的 DirectX 库是使用比您正在使用的旧版本 Visual Studio 编译的。 Microsoft 有时会更改其 C 运行时,从而在使用不同版本编译的库之间造成不兼容。 __vsnprintf
是旧版本 C 运行时的内部符号,在 2015 RC 版本中不存在。
不幸的是,dxerr.lib(连同 d3dx11.lib)现在已经 deprecated. You have two options - you can switch back to VS2013 or you can stop using functionality from dxerr.lib. The latter is probably better, because you can duplicate its functionality by using FormatMessage(链接文章中有更多信息)。
HACKY 但你可以修补 dxerr.lib。
将 __vsnprintf 替换为 _vsnprintf(末尾为空以说明开头删除的下划线)
您可以添加
,而不是手动破解 dxerr.lib#include <Windows.h>
#include <stdio.h>
int (WINAPIV * __vsnprintf)(char *, size_t, const char*, va_list) = _vsnprintf;
代码中的某处
遗留的 DirectX SDK 很旧,DXSDK 中的 dxerr.lib
与您遇到的 VS 2015 的 C 运行时不兼容。
一般来说,其中包含代码的静态库不能很好地与不同版本的编译器混合使用。旧版 DirectX SDK 中的大多数 .libs 都适用于 VS 2015,因为它们是 dll 或所有数据库的导入库,因此根本不包含任何代码。 DXSDK 自 VS 2010 以来未更新。
Aside: The VS team has made a heroic effort to keep the Visual C/C++ Runtime link compatible between VS 2015 Update 3, VS 2017, and VS 2019 per Microsoft Docs. This is not the normal pattern.
Be sure to read the instructions on Microsoft Docs on the proper way to mix the legacy DirectX SDK with the Windows 8.x SDK used by VS 2015. You are presumably using something else from the legacy DirectX SDK in this project besides dxerr.
我已经实现了一个 DXERR 版本,您可以在项目中从源代码构建它,以消除对旧版 DirectX SDK 的依赖。有关详细信息,请参阅 this post。也就是说,我故意只支持 Unicode(W 版本)。您可以很容易地弄清楚如何制作 ANSI(A 版本),但最好更新您的应用程序以使用 Unicode。
参见Where is the DirectX SDK (2021 Edition)? and DXUT for Direct3D 11。
更新: 正如在另一个答案中指出的那样 linking with legacy_stdio_definitions.lib
应该使旧的遗留 DirectX SDK 版本 dxerr.lib
link 再次使用 VS 2015/2017。也就是说,您应该尽可能地消除对遗留 DirectX SDK 的依赖,并且 DXERR 很容易被您自己的模块替换。参见 Living without D3DX。
我在使用 DXGetErrorMessage()
和 Dx9
时遇到了同样的问题,发现 MS 提供了一个额外的库来包含在 Additional Dependencies
属性页面中以解决这个问题。库名称是:legacy_stdio_definitions.lib
添加这个解决了我的问题。
您可以将平台工具集从 Visual Studio 2015 更改为 Visual Studio 2013,然后编译。 平台工具集位于项目属性的常规选项卡上。
只需添加
#pragma comment(lib, "legacy_stdio_definitions.lib")