注意#include

LNK2001 是要链接的目标没有找到,他管你是不是库。你在 main() 里只写一个 test(); 肯定报这个错,除非你自己写个 test() 函数。initguid.h 中定义了一个宏,其他的头文件里如果遇到了这个宏,则会对某个 CLSID 进行 定义,否则就只是 声明。你只有声明没有定义当然会链接找不到。不过好几个定义也不行,链接器不知道该连接哪个。所以,一个工程里,如果有多个 initguid.h 的包含,也会出问题。
-------------------------------------------
另一篇:
在没有包含Initguid.h的地方,DEFINE_GUID宏创建外部引用来使用GUID值,在包含Initguid.h的地方,DEFINE_GUID重定义DEFINE_GUID宏以产生GUID的定义。
如是没有在任何地方添加 Initguid.h,你会得到一个链接错误:"unresolved external symbol." ,如果同样的GUID包含Initguid.h两次,会得到编译错误"redefinition; multiple initialization."要解决这些问题,请确认Initguid.h只包含一次。同样的,不要包含Initguid.h到预编译头文件中去,因为预编译头文件会被每个源文件包含。
本文来自CSDN博客,转载请标明出处: http://blog.csdn.net/lxiongh/archive/2010/03/05/5350329.aspx
========================
另一篇:
// Src1.cpp #include #include "MyGuids.h" // Src2.cpp #include "MyGuids.h" // Src3.cpp #include "MyGuids.h" 其中在MyGuids.h必须使用 DEFINE_GUID(CLSID_MyObject, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); (Where this example has zeroes, put the actual GUID values.) You can use the Guidgen.exe utility to create a new GUID and paste it 其中initguid.h只能在一个.cpp中包含, DEFINE_GUID()宏定义了,如果包含了一个initguid.h,那么定义一个guid, 如果没有包含一个initguid.h ,则定义一个extern guid指向定义的那个guid, 所以项目中必须有一个文件.cpp包含initguid.h,否则会出错。但如果包含了多个的initguid.h,也会出错
*******************************************8
 问:

What library needs to be included for the PKEY_AudioEngine_DeviceFormat symbol to be recognized? I added some code to the WinAudio sample to try and get the PKEY_AudioEngine_DeviceFormat (for exclusive mode format negotiation) and I encounter a link error:

     error LNK2001: unresolved external symbol _PKEY_AudioEngine_DeviceFormat

回答:

It's defined via an INITGUID-style mechanism in mmdeviceapi.h

#include <initguid.h> // if this file is included
#include <mmdeviceapi.h> // then the GUIDs end up in this .obj file
回复:
Thank you. Doing this, and making sure that the GUID got initialized in only one source file (to avoid LNK2005 errors) fixed my problem.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值