简体   繁体   English

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

[英]Unresolved external symbol in MIDL COM library

My system is a Windows 10 64-bit fall creators edition with Visual Studio 2010 Professional. 我的系统是带有Visual Studio 2010 Professional的Windows 10 64位秋季创作者版。

I have a COM interface with the following IDL (ISomeInterface.idl): 我有一个带有以下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;
    };
};

Which I compile with this command: 我用以下命令编译:

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

Then I create a module definition file (ISomeInterface.def): 然后,我创建一个模块定义文件(ISomeInterface.def):

LIBRARY     "ISomeInterface"

EXPORTS
    DllGetClassObject       PRIVATE
    DllCanUnloadNow         PRIVATE
    DllRegisterServer       PRIVATE
    DllUnregisterServer     PRIVATE
    IID_ISomeInterface      DATA
    LIBID_ISomeInterfaceLib DATA

And I build my interface DLL using these commands: 然后使用以下命令构建接口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"Release\vc100.pdb" /Gd /TC /analyze- /errorReport:prompt dlldata.c ISomeInterface_i.c ISomeInterface_p.c

link "/OUT:Release\ISomeInterface.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:Release\ISomeInterface.dll.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" "/PDB:Release\ISomeInterface.pdb" /OPT:REF /OPT:ICF /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:Release\ISomeInterface.lib" /MACHINE:X86 /DLL Release\dlldata.obj Release\ISomeInterface_i.obj Release\ISomeInterface_p.obj

My issue is that when I create my ATL executable it keeps failing to link giving me this: 我的问题是,当我创建ATL可执行文件时,它始终无法链接,这给了我:

SomeApp.obj : error LNK2001: unresolved external symbol _LIBID_ISomeInterfaceLib

I am using #include "ISomeInterface.h" and have added ISomeInterface.lib to Linker->Input. 我正在使用#include "ISomeInterface.h" ,并将ISomeInterface.lib添加到Linker-> Input。

Running dumpbin.exe /exports Release\\ISomeInterface.dll provides the following: 运行dumpbin.exe /exports Release\\ISomeInterface.dll提供以下功能:

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


Dump of file Release\ISomeInterface.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

Running dumpbin.exe -headers Release\\ISomeInterface.lib | findstr /c:" Symbol name :" 运行dumpbin.exe -headers Release\\ISomeInterface.lib | findstr /c:" Symbol name :" dumpbin.exe -headers Release\\ISomeInterface.lib | findstr /c:" Symbol name :" shows that the symbol in in the LIB file: dumpbin.exe -headers Release\\ISomeInterface.lib | findstr /c:" Symbol name :"显示LIB文件中的符号:

  Symbol name  : _IID_ISomeInterface
  Symbol name  : _LIBID_ISomeInterfaceLib

If I use the ISomeInterface_i.c in the project and remove the LIB then it compiles fine, but I am attempting to get away from that... 如果我在项目中使用ISomeInterface_i.c并删除了LIB,那么它可以很好地编译,但是我正试图摆脱它。

So if I delete DATA from the module definition file the symbols link correctly it seems. 因此,如果我从模块定义文件中删除数据,则符号链接似乎正确。 new file: 新文件:

LIBRARY     "ISomeInterface"

EXPORTS
    DllGetClassObject       PRIVATE
    DllCanUnloadNow         PRIVATE
    DllRegisterServer       PRIVATE
    DllUnregisterServer     PRIVATE
    IID_ISomeInterface
    LIBID_ISomeInterfaceLib

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM