简体   繁体   中英

Unresolved external symbol in MIDL COM library

My system is a Windows 10 64-bit fall creators edition with Visual Studio 2010 Professional.

I have a COM interface with the following IDL (ISomeInterface.idl):

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):

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:

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:

SomeApp.obj : error LNK2001: unresolved external symbol _LIBID_ISomeInterfaceLib

I am using #include "ISomeInterface.h" and have added ISomeInterface.lib to Linker->Input.

Running dumpbin.exe /exports Release\\ISomeInterface.dll provides the following:

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 :" shows that the symbol in in the LIB file:

  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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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