VC 几种常见错误的workaround

本文介绍了解决Microsoft Visual C++编译器中出现的警告C4996及LNK2005错误的方法。针对警告,通过配置预处理器定义来禁用安全检查;对于链接错误,调整链接器输入设置以避免重复定义问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1>ClCompile:
1>  lib.cpp
1>  _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>d:\softwaredevelop\libjdungeon\libjdungeon\lib.cpp(58): warning C4996: 'std::basic_string<_Elem,_Traits,_Ax>::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\xstring(1555) : see declaration of 'std::basic_string<_Elem,_Traits,_Ax>::copy'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Ax=std::allocator<char>
1>          ]

Workaround: Solution Explorer ->项目右键-> properties ->Configuration Properties->C/C++ -> Preprocessor->

Preprocessor Definitions->下拉框<Edit...>  ->最末尾增加_SCL_SECURE_NO_WARNINGS

重新编译,即可。

 

1>  Generating Code...
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)

Description:  There are 'new' & 'delete' operators in both library ( uafxcwd.lib & LIBCMTD.lib).

Because LIBCMTD.lib have defined these operators, when uafxcwd.lib try to define them, the compiler complain.

Solution: 

Solution Explorer ->项目右键-> properties ->Configuration Properties->Linker->Input->

Additional Dependencies->uafxcwd.lib

(input uafxcw.lib when you configure release).

转载于:https://www.cnblogs.com/presbyter/p/11228306.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值