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之前加了下画线?
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之前加了下画线?
2. 编译idl生成的文件***.h和**_i.c加入到工程中。
3. 编译你的工程文件
unresolved external symbol _IID_ITaskMgr,因为编译器对symbol处理加一个下划线
将常规属性选项“在 ATL 中最小使用 CRT”设置为否
#include "YourATLProject_i.c"
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函数,郁闷。
没错,下划线是编译器加的。
IID_ITaskMgr编译后会变成_IID_ITaskMgr
#include "generated_i.c"
Does it work?
这和以前头文件的定义方式是一样的。
以前我们定义头文件开头是#ifndef ..........................这样就会避免重复编译,自然就避免了重复定义。我发了个帖子,申请当版主,请多多支持!
已经支持你了,呵呵。
比如文件里有这么一句
#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的初始化代码跳过去了。
比如文件里有这么一句
#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的初始化代码跳过去了。