MIDL COM库中未解决的外部符号

Unresolved external symbol in MIDL COM library

本文关键字:外部 符号 未解决 COM MIDL      更新时间:2023-10-16

我的系统是Windows 10 64位Fall Creator Edition,带有Visual Studio 2010 Professional。

我具有以下IDL(isomeinterface.idl(的com接口:

import "oaidl.idl";
import "ocidl.idl";
[
    object,
    uuid(61E246F6-3F22-404B-8EA8-E4D13F3206D6),
    pointer_default(unique)
]
interface ISomeInterface : IUnknown
{
    HRESULT DoSomething();
}
[
    uuid(7EF22D33-5C29-4D32-BFBC-0B276C5F7427),
    version(1.0),
    helpstring("ISomeInterface 1.0 Type Library")
]
library ISomeInterfaceLib
{
    importlib("stdole2.tlb");
    [
        uuid(BC91D238-B0E1-4FA2-AAC8-195D761DF9DC),
        version(1.0),
        helpstring("ISomeInterface Class")
    ]
    coclass ISomeInterfaceImpl
    {
        [default] interface ISomeInterface;
    };
};

我用此命令编译的:

midl /iid "ISomeInterface_i.c" /env win32 /h "ISomeInterface.h" /W1 /char signed /tlb "ReleaseISomeInterface.tlb" /Oicf /D "NDEBUG" /robust /nologo /proxy "ISomeInterface_p.c" ISomeInterface.idl

然后我创建一个模块定义文件(isOmeInterface.def(:

LIBRARY     "ISomeInterface"
EXPORTS
    DllGetClassObject       PRIVATE
    DllCanUnloadNow         PRIVATE
    DllRegisterServer       PRIVATE
    DllUnregisterServer     PRIVATE
    IID_ISomeInterface      DATA
    LIBID_ISomeInterfaceLib DATA

我使用以下命令构建接口DLL:

cl /c /Zi /W1 /WX- /O2 /Oy- /D WIN32 /D REGISTER_PROXY_DLL /D NDEBUG /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\" /Fd"Releasevc100.pdb" /Gd /TC /analyze- /errorReport:prompt dlldata.c ISomeInterface_i.c ISomeInterface_p.c
link "/OUT:ReleaseISomeInterface.dll" rpcns4.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "/DEF:ISomeInterface.def" /MANIFEST "/ManifestFile:ReleaseISomeInterface.dll.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" "/PDB:ReleaseISomeInterface.pdb" /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:ReleaseISomeInterface.lib" /MACHINE:X86 /DLL Releasedlldata.obj ReleaseISomeInterface_i.obj ReleaseISomeInterface_p.obj

我的问题是,当我创建我的ATL可执行文件时,它一直无法链接给我:

SomeApp.obj : error LNK2001: unresolved external symbol _LIBID_ISomeInterfaceLib

我正在使用#include "ISomeInterface.h",并已将ISomeInterface.lib添加到Linker->输入中。

运行dumpbin.exe /exports ReleaseISomeInterface.dll提供以下内容:

Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file ReleaseISomeInterface.dll
File Type: DLL
  Section contains the following exports for ISomeInterface.dll
    00000000 characteristics
    5ABD61A2 time date stamp Thu Mar 29 17:58:58 2018
        0.00 version
           1 ordinal base
           6 number of functions
           6 number of names
    ordinal hint RVA      name
          1    0 00001040 DllCanUnloadNow
          2    1 00001000 DllGetClassObject
          3    2 000010A0 DllRegisterServer
          4    3 000010E0 DllUnregisterServer
          5    4 000030E8 IID_ISomeInterface
          6    5 000030F8 LIBID_ISomeInterfaceLib
  Summary
        1000 .data
        1000 .orpc
        1000 .rdata
        1000 .reloc
        1000 .text

运行dumpbin.exe -headers ReleaseISomeInterface.lib | findstr /c:" Symbol name :"显示LIB文件中的符号:

  Symbol name  : _IID_ISomeInterface
  Symbol name  : _LIBID_ISomeInterfaceLib

如果我在项目中使用ISomeInterface_i.c并删除LIB,则可以很好地编译,但是我试图摆脱...

因此,如果我从模块定义文件中删除数据,则符号链接似乎正确。新文件:

LIBRARY     "ISomeInterface"
EXPORTS
    DllGetClassObject       PRIVATE
    DllCanUnloadNow         PRIVATE
    DllRegisterServer       PRIVATE
    DllUnregisterServer     PRIVATE
    IID_ISomeInterface
    LIBID_ISomeInterfaceLib