vs2015 中无法链接strcasecmp 和 strncasecmp的解决办法

原因:strcasecmp是BSD/POSIX标准,非ANSI标准,所以微软并不支持。

strcasecmp最早出现在4.4BSD,后来加入到Posix标准里。MS的一直用_stricmp函数,功能完全一样。

方案一:stricmp替换strcasecmp ;strnicmp替换strncasecmp,即可。

之后貌似还会报错:

   error C4996: 'strnicmp': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strnicmp. See online         help for details. D:\CAFFE_ROOT\src\caffe\common.cpp

解决办法:

这个问题在VS 2012之前的版本中是不会当做错误的,只是提出一个警告。为了避免报错,可以使用以下两个宏定义来屏蔽掉这种        错误。

在common.cpp文件的属性->c/c++->预处理器->预处理器定义   中添加:

    _CRT_SECURE_NO_DEPRECATE 

    _CRT_NONSTDC_NO_DEPRECATE 

方案二:用VC SDK中的函数来代替,在main函数外面步添加一下代码即可:

#ifdef _MSC_VER
#define strcasecmp stricmp
#define strncasecmp  strnicmp 
#endif

方案三:自己添加该函数的声明和定义

第一步:.h文件添加:

#ifdef _MSC_VER
int strcasecmp(char *s1, char *s2);
int strncasecmp(char *s1, char *s2, register int n);
#endif
第二部:.c文件中添加
#ifdef _MSC_VER
int strcasecmp(char *s1, char *s2)
{
   while  (toupper((unsigned char)*s1) == toupper((unsigned char)*s2++))
       if (*s1++ == '') return 0;
   return(toupper((unsigned char)*s1) - toupper((unsigned char)*--s2));
}

int strncasecmp(char *s1, char *s2, register int n)
{
  while (--n >= 0 && toupper((unsigned char)*s1) == toupper((unsigned char)*s2++))
      if (*s1++ == '')  return 0;
  return(n < 0 ? 0 : toupper((unsigned char)*s1) - toupper((unsigned char)*--s2));
}
#endif



  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

焱齿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值