Creating Type Library...
Processing C:\MyDocuments\MyProjects\G\Sock\ISock.idl
ISock.idl
Processing E:\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing E:\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl
Linking...
GTaskMgr.obj : error LNK2001: unresolved external symbol _IID_ITaskMgr
Debug/Sock.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...Sock.dll - 2 error(s), 0 warning(s)
我查看/p选项产生的GTaskMgr.i文件,并没有引用符号_IDD_ITaskMgr呀(IID_ITaskMgr倒是有)。
说明:我的工程是普通的win32 dll工程,不是atl工程。
为何IDD_ITaskMgr之前加了下画线?

解决方案 »

  1.   

    我也碰到这种情况,当时好象是使用一个ACTIVEX 控件时出现这种情况,我只是把IID_ITaskMgr改成_IDD_ITaskMgr就行了,到底为什么我也不知道,好象是宏定义的时候出问题,具体怎样,我不清楚,你试试看,行不行~~
      

  2.   

    1. 编译idl文件,然后把.idl文件从工程中移出
    2. 编译idl生成的文件***.h和**_i.c加入到工程中。
    3. 编译你的工程文件
      

  3.   

    IID_ITaskMgr是在**_i.c(idl编译生成的文件)中定义的
    unresolved external symbol _IID_ITaskMgr,因为编译器对symbol处理加一个下划线
      

  4.   

    去掉_ATL_MIN_CRT
    将常规属性选项“在 ATL 中最小使用 CRT”设置为否
      

  5.   

    If you use ATL
    #include "YourATLProject_i.c"
      

  6.   

    我已经在另一个cpp文件里包含了ISock_i.c文件,可里面定义为IID_ITaskMgr,没在前面加下画线呀。
      

  7.   

    MSDN中说
    Note   When building a Release version of a project, you can get the following link error:LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
    This error occurs if you are using CRT functions that require CRT startup code. The Release configurations define _ATL_MIN_CRT, which excludes CRT startup code from your EXE or DLL. To avoid this error, do one of the following: Remove _ATL_MIN_CRT from the list of preprocessor defines to allow CRT startup code to be included. On the Project menu, click Settings. In the Settings For: drop-down list, choose Multiple Configurations. In the Select project configuration(s) to modify dialog box that appears, click the check boxes for all Release versions, and then click OK. On the C/C++ tab, choose the General category, then remove _ATL_MIN_CRT from the Preprocessor definitions edit box.
    If possible, remove calls to CRT functions that require CRT startup code and use their Win32 equivalents. For example, use lstrcmp instead of strcmp. Known functions that require CRT startup code are some of the string and floating point functions. 可我的不是ATL工程,工程设置里并没有_ATL_MIN_CRT宏定义呀,我也没有用CRT函数,郁闷。
      

  8.   

    // 我已经在另一个cpp文件里包含了ISock_i.c文件,可里面定义为IID_ITaskMgr,没在前面加下画线呀。
    没错,下划线是编译器加的。
    IID_ITaskMgr编译后会变成_IID_ITaskMgr
      

  9.   

    include那个文件后,编译还有问题?
      

  10.   

    只include了由ISock.idl生成的头文件。
      

  11.   

    #include "generatedheader.h"
    #include "generated_i.c"
      

  12.   

    记住了是include,而不是加入到工程中
      

  13.   

    ISock_i.c由另一个cpp文件包含编译了。GTaskMgr.cpp没有包含,只包含ISock.h文件
      

  14.   

    哪个文件用IID_ITaskMgr了,就#include "ISock_i.c"
    Does it work?
      

  15.   

    GTaskMgr.cpp包含了ISock_i.c之后没问题了,不会每个cpp用到ISock.h的都要包含ISock_i.c吧?
      

  16.   

    为何要每个cpp都要包含?这个为何不会出现重复定义?
      

  17.   

    最好是在stdafx.h中加支持我做版主吧,呵呵
      

  18.   

    你看看生成的.c文件就知道了,有很多的#ifndef  #ifdefine之类的。
    这和以前头文件的定义方式是一样的。
    以前我们定义头文件开头是#ifndef ..........................这样就会避免重复编译,自然就避免了重复定义。我发了个帖子,申请当版主,请多多支持!
      

  19.   

    可是多个cpp独立包含x_i.c文件,#ifndef 什么的挡不住呀,会在编译每个cpp时都编译x_i.c文件,这样在link时不会报重复定义?
      

  20.   

    http://community.csdn.net/Expert/topic/3403/3403763.xml?temp=.3434259
      

  21.   

    你想想,你多个CPP文件包含同一个.h文件,不照样没问题嘛!
      

  22.   

    h文件里的东西只是申明,不是定义呀。是不是const IID IID_ITaskMgr = {0x5A86A901,0xB30B,0x4d6c,{0x91,0x11,0xF7,0x55,0x37,0xFA,0x86,0xA2}};并不是真正的定义,就像const int c = 0一样不占存储空间?IID这样的结构体也可以这样定义?
    已经支持你了,呵呵。
      

  23.   

    呵呵,道理一样。
    比如文件里有这么一句
    #ifndef abc
    #define abc
    const IID IID_ITaskMgr = {0x5A86A901,0xB30B,0x4d6c,{0x91,0x11,0xF7,0x55,0x37,0xFA,0x86,0xA2}};
    #endif其中有a.cpp, b.cpp, c.cpp已用了这个文件。
    编译器要一个一个编译。比如说先编译a.cpp,它看到abc没有定义,它马上就定义了abc,然后初始化IID。然后它开始编译b.cpp,编译器一看abc已经定义了(编译a.cpp时定义的),它就把后面对IID的初始化代码跳过去了。
      

  24.   

    呵呵,道理一样。
    比如文件里有这么一句
    #ifndef abc
    #define abc
    const IID IID_ITaskMgr = {0x5A86A901,0xB30B,0x4d6c,{0x91,0x11,0xF7,0x55,0x37,0xFA,0x86,0xA2}};
    #endif其中有a.cpp, b.cpp, c.cpp已用了这个文件。
    编译器要一个一个编译。比如说先编译a.cpp,它看到abc没有定义,它马上就定义了abc,然后初始化IID。然后它开始编译b.cpp,编译器一看abc已经定义了(编译a.cpp时定义的),它就把后面对IID的初始化代码跳过去了。
      

  25.   

    编译a.cpp定义的东东在编译b.cpp时还可见吗?不是吧,你把const去掉,还是会报重复定义。