简体   繁体   English

错误 LNK2001:Visual Studio 2019 中未解析的外部符号 CWbemProviderGlue::FrameworkLogoffDLL(wchar_t const *)"

[英]error LNK2001: unresolved external symbol CWbemProviderGlue::FrameworkLogoffDLL(wchar_t const *)" in Visual Studio 2019

Have some code originally designed for Windows 2000 and the WMI SDK.有一些最初为 Windows 2000 和 WMI SDK 设计的代码。 I am trying to resolve the linker error.我正在尝试解决 linker 错误。 After trying the options referneced in What is an undefined reference/unresolved external symbol error and how do I fix it?在尝试了什么是未定义的引用/未解决的外部符号错误中引用的选项后,我该如何解决? was unable to find a solution.无法找到解决方案。

The unresolved symbols error:未解决的符号错误:

1>WmiProvider.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Provider::Provider(wchar_t const *,wchar_t const *)" (__imp_??0Provider@@QAE@PB_W0@Z)
1>WmiProvider.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall CInstance::SetCHString(wchar_t const *,char const *)" (__imp_?SetCHString@CInstance@@QAE_NPB_WPBD@Z)
1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __stdcall CWbemProviderGlue::FrameworkLogoffDLL(wchar_t const *)" (__imp_?FrameworkLogoffDLL@CWbemProviderGlue@@SGHPB_W@Z)
1>dllmain.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(wchar_t const *)" (__imp_?FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z)

I've tried adding code:我试过添加代码:

#pragma comment(lib,"Framedyn.lib")

and tried adding to lib to framedyn.lib linker options but still get same error.并尝试将 lib 添加到framedyn.lib linker 选项,但仍然出现相同的错误。

The project has the following defined to allow running on Windows XP:该项目定义了以下内容以允许在 Windows XP 上运行:

#define _WIN32_WINNT 0x0501

Project settings include:项目设置包括:

  • Target Platform Version 7.0目标平台版本 7.0
  • Platform Toolset Visual Studio 2017 - Windows XP (v141_xp)平台工具集 Visual Studio 2017 - Windows XP (v141_xp)
  • C++ Language Standard Default (ISO C++14 Standard7) C++ 语言标准默认值(ISO C++14 标准7)
  • Language - Conformance Mode - No语言 - 一致性模式 - 否
  • Target X86目标 X86

Example usage:示例用法:

case DLL_PROCESS_ATTACH:
    ghModule = hInstDLL;
    bRet = CWbemProviderGlue::FrameworkLoginDLL(L"WmiProvider");
    break;

CL.exe and MSBUILD.exe load WbemGlue.h from: CL.exe 和 MSBUILD.exe 从以下位置加载WbemGlue.h

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\WbemGlue.h C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\WbemGlue.h

link.exe loads FrameDyn.lib from: link.exe 从以下位置加载FrameDyn.lib

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib

dumpbin /exports "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib" shows entry for FrameworkLoginDLL as: dumpbin /exports "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\FrameDyn.Lib" 将 FrameworkLoginDLL 的条目显示为:

?FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG@Z (public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *))
?FrameworkLoginDLL@CWbemProviderGlue@@SGHPBGPAJ@Z (public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *,long *))

Looking at the symbols difference is when I compile visual studio is looking for FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z whereas the lib file has a G at the end and no W ie **FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG @Z**查看符号差异是当我编译 Visual Studio 时正在寻找FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z而 lib 文件末尾有一个 G 并且没有W ie **FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG @Z**

The old MSDN documentation (from August 2001) specifies this use:旧的 MSDN 文档(从 2001 年 8 月开始)指定了这种用途:

The FrameworkLoginDLL method is called when the DLL_PROCESS_ATTACH value is sent to DllMain to determine whether the provider server can be loaded.当将 DLL_PROCESS_ATTACH 值发送到 DllMain 以确定是否可以加载提供程序服务器时调用 FrameworkLoginDLL 方法。

static BOOL WINAPI CWbemProviderGlue::FrameworkLoginDLL(
  LPCWSTR name
);

Requires:要求:

  • Windows NT/2000/XP: Included in Windows NT 4.0 SP4 and later. Windows NT/2000/XP:包含在 Windows NT 4.0 SP4 及更高版本中。
  • Windows 95/98/Me: Included in Windows 95 and later. Windows 95/98/Me:包含在 Windows 95 及更高版本中。
  • Header: Declared in WbemGlue.h; Header:在 WbemGlue.h 中声明; include FwCommon.h.包括 FwCommon.h。
  • Library: Use Framedyn.lib.库:使用 Framedyn.lib。

The current documentation here specifies use: 此处的当前文档指定使用:

BOOL FrameworkLoginDLL(
  LPCWSTR name
);

With following requirements:有以下要求:

  • Minimum supported client Windows Vista支持的最低客户端 Windows Vista
  • Minimum supported server Windows Server 2008最低支持服务器 Windows 服务器 2008
  • Target Platform Windows Header wbemglue.h (include FwCommon.h)目标平台 Windows Header wbemglue.h(包括 FwCommon.h)
  • Library FrameDyn.lib库 FrameDyn.lib
  • DLL FrameDynOS.dll; DLL FrameDynOS.dll; FrameDyn.dll FrameDyn.dll

Creating a new Visual Studio 2019 Project with Desktop C++ Wizard, selecting DLL, and all other defaults reproduces same issue with this code:使用桌面 C++ 向导创建新的 Visual Studio 2019 项目,选择 DLL 和所有其他默认值,使用此代码重现相同的问题:

#include "framework.h"
#include <FwCommon.h>
#pragma comment(lib,"FrameDyn.lib")
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    BOOL bRet = TRUE;

    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        bRet = CWbemProviderGlue::FrameworkLoginDLL(L"WmiProvider");

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return bRet;
}

Demangling the symbol linker is trying to use get the following:拆解符号 linker 正在尝试使用获取以下内容:

__imp_public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(wchar_t const *)

Demangling the symbol in actual.lib file:对实际.lib 文件中的符号进行拆解:

public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *)

Definition in WbemGlue.h WbemGlue.h 中的定义

static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name);

This issue occurred because MSVC was looking for symbol FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z but the lib file had definition FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG@Z .出现此问题是因为 MSVC 正在寻找符号FrameworkLoginDLL@CWbemProviderGlue@@SGHPB_W@Z但 lib 文件具有定义FrameworkLoginDLL@CWbemProviderGlue@@SGHPBG@Z

Demangling the names using https://demangler.com/ showed the symbol used by MSVC was:使用https://demangler.com/对名称进行拆解显示 MSVC 使用的符号是:

__imp_public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(wchar_t const *)

Where as the lib file was: lib文件在哪里:

public: static int __stdcall CWbemProviderGlue::FrameworkLoginDLL(unsigned short const *)

This issue was resolved by setting Project Properties under C/C++ - Language - Treat WChart As Built in Type to No (/Zc:wchar_t-)通过将C/C++ - Language - Treat WChart As Built in Type下的 Project Properties 设置为No (/Zc:wchar_t-)解决了这个问题

在此处输入图像描述

Microsoft recommends the following regarding this setting here : Microsoft 在此处建议有关此设置的以下内容:

If /Zc:wchar_t is on, wchar_t is a keyword for a built-in integral type in code compiled as C++.如果 /Zc:wchar_t 打开,wchar_t 是编译为 C++ 的代码中内置整数类型的关键字。 If /Zc:wchar_t- (with a minus sign) is specified, or in code compiled as C, wchar_t is not a built-in type.如果指定了 /Zc:wchar_t-(带减号),或者在编译为 C 的代码中,wchar_t 不是内置类型。 Instead, wchar_t is defined as a typedef for unsigned short in the canonical header stddef.h.相反,wchar_t 在规范 header stddef.h 中被定义为 unsigned short 的 typedef。 (The Microsoft implementation defines it in another header that is included by stddef.h and other standard headers.) (Microsoft 实现在 stddef.h 和其他标准头文件中包含的另一个 header 中对其进行了定义。)

We do not recommend /Zc:wchar_t- because the C++ standard requires that wchar_t be a built-in type.我们不推荐 /Zc:wchar_t- 因为 C++ 标准要求 wchar_t 是内置类型。 Using the typedef version can cause portability problems.使用 typedef 版本可能会导致可移植性问题。 If you upgrade from earlier versions of Visual Studio and encounter compiler error C2664 because the code is trying to implicitly convert a wchar_t to unsigned short, we recommend that you change the code to fix the error, instead of setting /Zc:wchar_t-.如果您从早期版本的 Visual Studio 升级并遇到编译器错误 C2664,因为代码试图将 wchar_t 隐式转换为 unsigned short,我们建议您更改代码以修复错误,而不是设置 /Zc:wchar_t-。

The /Zc:wchar_t option is on by default in C++ compilations, and is ignored in C compilations. /Zc:wchar_t 选项在 C++ 编译中默认打开,在 C 编译中被忽略。 The /permissive- option does not affect /Zc:wchar_t. /permissive- 选项不影响 /Zc:wchar_t。

Microsoft implements wchar_t as a two-byte unsigned value. Microsoft 将 wchar_t 实现为两字节无符号值。 It maps to the Microsoft-specific native type __wchar_t.它映射到 Microsoft 特定的本机类型 __wchar_t。 For more information about wchar_t, see Data Type Ranges and Fundamental Types.有关 wchar_t 的更多信息,请参阅数据类型范围和基本类型。

If you write new code that has to interoperate with older code that still uses the typedef version of wchar_t, you can provide overloads for both the unsigned short and __wchar_t variations of wchar_t, so that your code can be linked with code compiled with /Zc:wchar_t or code compiled without it.如果您编写的新代码必须与仍然使用 wchar_t 的 typedef 版本的旧代码互操作,您可以为 wchar_t 的 unsigned short 和 __wchar_t 变体提供重载,以便您的代码可以与使用 /Zc 编译的代码链接: wchar_t 或没有它编译的代码。 Otherwise, you would have to provide two different builds of the library, one with and one without /Zc:wchar_t enabled.否则,您将必须提供两种不同的库版本,一种启用/Zc:wchar_t 启用,另一种未启用/Zc:wchar_t。 Even in this case, we recommend that you build the older code by using the same compiler that you use to compile the new code.即使在这种情况下,我们也建议您使用用于编译新代码的相同编译器来构建旧代码。 Never mix binaries compiled with different compilers.切勿混合使用不同编译器编译的二进制文件。

When /Zc:wchar_t is specified, _WCHAR_T_DEFINED and _NATIVE_WCHAR_T_DEFINED symbols are defined.当指定 /Zc:wchar_t 时,定义了 _WCHAR_T_DEFINED 和 _NATIVE_WCHAR_T_DEFINED 符号。 For more information, see Predefined Macros.有关详细信息,请参阅预定义宏。

If your code uses the compiler COM global functions, because /Zc:wchar_t is now on by default, we recommend that you change explicit references to comsupp.lib (either from the comment pragma or on the command line) to either comsuppw.lib or comsuppwd.lib.如果您的代码使用编译器 COM 全局函数,因为 /Zc:wchar_t 现在默认打开,我们建议您将对 comsupp.lib 的显式引用(从注释编译指示或命令行上)更改为 comsuppw.lib 或comsuppwd.lib。 (If you must compile with /Zc:wchar_t-, use comsupp.lib.) If you include the comdef.h header file, the correct library is specified for you. (如果必须使用 /Zc:wchar_t- 进行编译,请使用 comsupp.lib。)如果包含 comdef.h header 文件,则会为您指定正确的库。 For information about compiler COM support, see Compiler COM Support.有关编译器 COM 支持的信息,请参阅编译器 COM 支持。

The wchar_t built-in type is not supported when you compile C code.编译 C 代码时不支持 wchar_t 内置类型。 For more information about conformance issues with Visual C++, see Nonstandard Behavior.有关 Visual C++ 的一致性问题的更多信息,请参阅非标准行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误LNK2001:无法解析的外部符号 - error LNK2001: unresolved external symbol 错误LNK2001:无法解析的外部符号 - error LNK2001: unresolved external symbol 链接错误LNK2001:无法解析的外部符号(Visual Studio 2008) - Linking error LNK2001: unresolved external symbol (Visual Studio 2008) Visual Studio 2012,C / C ++代码,错误LNK2001:无法解析的外部符号 - Visual Studio 2012, C/C++ code, error LNK2001: unresolved external symbol Visual Studio 2010:C ++:错误LNK2001:未解析的外部符号 - Visual Studio 2010: C++: Error LNK2001: unresolved external symbol Visual Studio错误LNK2001:未解析的外部符号_fgetc_unlocked - Visual Studio error LNK2001: unresolved external symbol _fgetc_unlocked 错误LNK2001:未解析的外部符号“int const * const A_array”当我在定义文件中不包含标头时 - error LNK2001: unresolved external symbol “int const * const A_array” when I don't include the header in the definition file 使用Visual Studio 2012中的GnuTLS 3.1.6时遇到“错误LNK2001:无法解析的外部符号_gnutls_free” - Getting “error LNK2001: unresolved external symbol _gnutls_free” when using GnuTLS 3.1.6 from Visual Studio 2012 错误LNK2001:无法解析的外部符号“ public:静态类sf :: RenderStates const sf :: RenderStates :: Default” - error LNK2001: unresolved external symbol “public: static class sf::RenderStates const sf::RenderStates::Default” Visual Studio 2010:错误LNK2001:无法解析的外部符号:sapi.h和KINECT的Microsoft Speech SDK - Visual Studio 2010 : error LNK2001: unresolved external symbol : sapi.h and Microsoft Speech SDK for KINECT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM