原文转自 https://www.cnblogs.com/xiongjiaji/archive/2010/12/31/2476565.html

今天用VS2005编译DirectShow程序,发现出来很多莫名其妙的链接错误:如下:
 
error LNK2001: 无法解析的外部符号 "public: virtual long __stdcall CBaseFilter::FindPin(wchar_t const *,struct IPin * *)" (?FindPin@CBaseFilter@@UAGJPB_WPAPAUIPin@@@Z)
error LNK2001: 无法解析的外部符号 "public: virtual long __stdcall CBaseFilter::JoinFilterGraph(struct IFilterGraph *,wchar_t const *)" (?JoinFilterGraph@CBaseFilter@@UAGJPAUIFilterGraph@@PB_W@Z)
error LNK2001: 无法解析的外部符号 "public: virtual long __stdcall CBaseFilter::QueryVendorInfo(wchar_t * *)" (?QueryVendorInfo@CBaseFilter@@UAGJPAPA_W@Z)

上网一查,发现如下设置即可:
C/C++ | Language | Treat wchar_t as built-in type: yes?no?
默认为是,设置为否即可

在我的项目中正好相反,默认是 否,有上面的问题,改成是则编译成功。

(1) 为什么会出现这种错误呢?是因为VC6以及VS2003在wchar_t内置的选项上默认为No,而VS2005在此选项上默认为Yes,我今天使用VS2005打开原来VS2003建立的BaseClass项目,使得选项为No,这样编译出来的基类库的选项就是No了。
    然后,在使用VS2005新建DirectShow程序时,默认选项为Yes,这样程序与基类的选项就不一致了,在函数的参数涉及到wchar_t时,程序的链接会由于生成的名字不同而导致链接不上(同样是wchar_t,链接时lib文件的符号是不同的)。
    弄清楚这个问题之后,此选项的选择就无所谓了,只要工程和Lib在该选项上一致即可

(2) 通过查看定义CBasefilter类的头文件(amfilter.h)我发现其中关于构造函数的定义有如下代码 
C/C++ code public: CBaseFilter( const TCHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid); // The clsid to be used to serialize this filter CBaseFilter( TCHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid, // The clsid to be used to serialize this filter HRESULT *phr); // General OLE return code #ifdef UNICODE CBaseFilter( const CHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid); // The clsid to be used to serialize this filter CBaseFilter( CHAR *pName, // Object description LPUNKNOWN pUnk, // IUnknown of delegating object CCritSec *pLock, // Object who maintains lock REFCLSID clsid, // The clsid to be used to serialize this filter HRESULT *phr); // General OLE return code #endif 
所以我想,vs默认编码就是unicode的,所以应该用的构造函数时下面两个,于是我把调用CBasefilter构造函数的地方改成 
C/C++ code CBaseFilter("NetSender", lpunk, &mFilterLock, CLSID_NetSender) 
原来是 
C/C++ code CBaseFilter(NAME("NetSender"), lpunk, &mFilterLock, CLSID_NetSender) 
其他的构造函数的调用也进行相应的改造,果然将这些link error都给kill掉了^_^ 
但是还有一处有问题就是关于CPosPassThru这个构造函数,这个类的构造函数没有定义unicode版本的,只有这样一个构造函数 
C/C++ code CPosPassThru(const TCHAR *, LPUNKNOWN, HRESULT*, IPin *); 
我去掉NAME宏以后出现如下错误 
C/C++ code error C2664: 'CPosPassThru::CPosPassThru(const TCHAR *,LPUNKNOWN,HRESULT *,IPin *)' : cannot convert parameter 1 from 'const char [13]' to 'const TCHAR *' 
我使用NAME宏的话,又出现连接错误 
C/C++ code error LNK2028: unresolved token (0A00024D) "public: __thiscall CPosPassThru::CPosPassThru(unsigned short const *,struct IUnknown *,long *,struct IPin *)" (??0CPosPassThru@@$$FQAE@PBGPAUIUnknown@@PAJPAUIPin@@@Z) 
也就是说,它认为我给它传入的第一个参数是一个unsigned short const char*类型 
1,请问为什么我使用NAME宏,它会认为我使用的是unsigned short const char*类型,NAME宏不就是TEXT宏么,而TEXT宏不就是可以将常量字符创转换成TCHAR*么? 
2,如何解决这个问题,我想也就是如何将unsigned short const char*转换成TCHAR*的问题。

error LNK2001: 无法解析的外部符号 "public: virtual long __stdcall CBaseFilter(转)的更多相关文章

  1. main.obj:-1: error: LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __thiscall CustomButton::metaObject(void)const " (?metaObject@CustomButton@@UBEPBUQMetaObject@@XZ)

    QTCreator 运行时报错 main.obj:-1: error: LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject cons ...

  2. vs2010+qt4编译出现error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject等错误

    1.当vs2010编译qt时会出现以下错误: 1>------ 已启动全部重新生成: 项目: MyDialog, 配置: Debug Win32 ------            1>生 ...

  3. 虚函数 error LNK2001: 无法解析的外部符号 "public: virtual void __cdecl

    在虚函数后面加一对大括号 #ifndef CAFFE_CONV_DW_LAYER_HPP_ #define CAFFE_CONV_DW_LAYER_HPP_ #include <vector&g ...

  4. error LNK2001: 无法解析的外部符号 "public: char * __thiscall

    error LNK2001: 无法解析的外部符号 "public: char * __thiscall CamPinPadCtrl::KeysConvert(unsigned long,ch ...

  5. 无法解析的外部符号 "public: virtual struct CRuntimeClass * _

    SetupPropertyPage.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct CRuntimeClass * __this ...

  6. C++工程编译之“error LNK2001: 无法解析的外部符号”

    今天一整天都在折腾“error LNK2001: 无法解析的外部符号”,就在头疼不已的时候,总算是找到问题原因了:各个动态链接库的编译方式必须统一才行,要不然很容易对库函数的引用产生冲突.简单来说就是 ...

  7. error LNK2001: 无法解析的外部符号

    1.错误描述 error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl PadSystem::Private::printQS ...

  8. error LNK2001: 无法解析的外部符号 _IID_IDirectDraw7

    工程使用了DirectDraw,编译出错 error LNK2001: 无法解析的外部符号 _IID_IDirectDraw7 解决办法是吧dxguid.lib添加到工程中,把lib所在目录添加到工程 ...

  9. error LNK2019: 无法解析的外部符号 "public:

    错误 1 error LNK2019: 无法解析的外部符号 "public: __thiscall test::test(void)" (??0test@@QAE@XZ),该符号在 ...

随机推荐

  1. source insight插件

    直使用sourceinsight编辑C/C++代码,sourceinsight是一个非常好用的编辑工具可以任意定位,跳转,回退,本人一直 使用该工具做C/C++开发,sourceinsight能够满足 ...

  2. C++ 无符号整型和整型的区别

    在Win 7系统中,short 表示的范围为 - 32767到 32767,而无符号的short表示的范围为0 到 65535,其他类型的同理可推导出来,当然,仅当数字不为负的时候才使用无符号类型. ...

  3. Evevt Loop、任务队列、定时器等

    上周五,一个朋友发给我一道面试题,代码如下: console.log(1); setTimeout(console.log(2), 0); Promise.resolve().then(res =&g ...

  4. js石头剪刀布小游戏

    代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title ...

  5. Git-改变历史

    悔棋 在日常的Git操作中,会经常出现这样的状况,输入git commit命令刚刚敲下回车键就后悔了:可能是提交说明中出现了错别字,或者有文件忘记提交,或者有的修改不应该提交,诸如此类. Git提供了 ...

  6. 洛谷P1451 求细胞数量

    求细胞数量 题目链接 这道题大概是一个最简单的联通块的题了qwq 注意枚举起点的时候 一定不要从0开始不然你就会从0进入到了其他联通块中从而多查. 一定看清题意这道题不是同色为联通块!!! AC代码如 ...

  7. 网络策略中使用的 VLAN 属性

    TechNet 库 Windows Server Windows Server 2008 R2 und Windows Server 2008 按类别提供的 Windows Server 内容 Win ...

  8. 为什么要搞vim

    一. 先得想清楚折腾vim受的这顿折磨值不值.值.零碎记录几点. 迫使我使用vim的原因如下: (1)之前实习的公司的开发机上只有vim,以后工作的公司也只有vim,同部门的同事大都用vim:如果不用 ...

  9. Percona-Tookit工具包之pt-table-usage

      Preface       There always be some table join operations in our SQL statement.Although we can know ...

  10. appium 多个设备同时执行

    测试需要同时在多个android设备上运行,就需要启动多个appium 使用adb命令获取udid,命令:adb get-serialno 使用的是testng测试框架,代码使用java编写 第一台, ...