向C++进发

首先,从大家常见的连接错误开始吧

 

1.error LNK2019: can not resolve external label "void __cdecl `eh vector destructor iterator'

解决:#pragma comment(lib, "ccrtrtti.lib")
 
 
2.error LNK2001: unresolved external symbol __security_cookie
error LNK2001: unresolved external symbol __security_check_cookie
解决:打开设置->C/C++->Code Generation->Buffer Security Check改为NO (/GS-)
 
3.unresolved external symbol wmain referenced in function mainWCRTStartup
解决:到中project Settings将Link >> Advanced >> entry-point  改为WinMainCRTStartup。

 

4.error LNK2001: unresolved external symbol "unsigned int (__stdcall* ATL::g_pfnGetThreadACP)(void)" (?g_pfnGetThreadACP@ATL@@3P6GIXZA)

解决:#pragma comment(lib, "atlsd.lib")

 

5. error   LNK2001:   unresolved   external   symbol   IID_IPOutlookApp  

    error   LNK2001:   unresolved   external   symbol   CLSID_Application  

解决方案:

加上如下定义

#define   INITGUID  
  #include   <windows.h>    
  #include   <objbase.h>  
  #include   <initguid.h>  
  #include   <Pimstore.h>

 

6.在VS2005中添加vector容器时,包含了头文件vector和using namespace std后还是出现了以后链接错误。

error LNK2001: unresolved external symbol "const type_info::`vftable&apos;" (??_7type_info@@6B@)

 error LNK2001: unresolved external symbol "const type_info::`vftable&apos;" (??_7type_info@@6B@)

error LNK2001: unresolved external symbol "public: __cdecl std::exception::exception(class std::exception const &)" (??0exception@std@@QAA@ABV01@@Z)

error LNK2001: unresolved external symbol "public: __cdecl std::exception::exception

解决方案:

#pragma comment(lib, "ccrtrtti.lib")

 

7.fatal error LNK1112: module machine type 'THUMB' conflicts with target machine type 'ARM'

 

解决方案:

打开Linker选项里的command line输入 /subsystem:windowsce,5.01或 //subsystem:windowsce,5.02

(分别是windows mobile 5.0和windows mobile 6.0)

 

编译错误

一。

1. 错误输出

    ./zlibrary/ui/src/win32/w32widgets/W32VBorderBox.cpp(114) : error C2589: “(”: “::”右边的非法标记
    ./zlibrary/ui/src/win32/w32widgets/W32VBorderBox.cpp(114) : error C2059: 语法错误 : “::”
2. 错误代码举例

   view plaincopy to clipboardprint?
size.Width = std::max(size.Width, elementSize.Width); 
size.Width = std::max(size.Width, elementSize.Width);

3. 函数模板max  

   view plaincopy to clipboardprint?
template<class _Ty> inline  
    const _Ty& (__CLRCALL_OR_CDECL max)(const _Ty& _Left, const _Ty& _Right)  
    {   // return larger of _Left and _Right  
    return (_DEBUG_LT(_Left, _Right) ? _Right : _Left);  
    } 
template<class _Ty> inline
 const _Ty& (__CLRCALL_OR_CDECL max)(const _Ty& _Left, const _Ty& _Right)
 { // return larger of _Left and _Right
 return (_DEBUG_LT(_Left, _Right) ? _Right : _Left);
 }   

   注:模板就是实现代码重用机制的一种工具,它可以实现类型参数化,即把类型定义为参数, 从而实现了真正的代码可重用性。模版可以分为两类,一个是函数模版,另外一个是类模版。

4. 错误原因

   函数模板max与Visual C++中的全局的宏max冲突。

5. 解决办法

    第一种办法:设置项目属性,在预定义处理器中添加定义NOMINMAX来禁止使用Vsual C++的min/max宏定义。

                       项目属性   ——> C/C++ ——> 预处理器 ——> 预处理器定义 (此处添加预定义编译开关   NOMINMAX)

    第二种办法: 加上括号,与Vsual C++的min/max宏定义区分开

                       view plaincopy to clipboardprint?
size.Width = std::max(size.Width, elementSize.Width); 
size.Width = std::max(size.Width, elementSize.Width);

                       修改为:

                       view plaincopy to clipboardprint?
size.Width = (std::max)(size.Width, elementSize.Width); 

 持续更新中。。。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值