在msdn里面(http://msdn.microsoft.com/en-us/library/ms235365(VS.80).aspx)有这么一段话:
These POSIX functions are deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l instead.
意思是在Visual C++ 2005以后,stricmp, wcsicmp被_stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l等替代了。
我在编译libidn的时候,发现在命令行里面链接时会出现错误:
libidn.lib(idna.obj) : error LNK2019: unresolved external symbol __imp__stricmp
referenced in function _idna_to_unicode_internal
而这句话在vs 2005 ide里面却不会出现。
但我把libidn-1.9/win32/include/config.h里面的
#define strcasecmp stricmp
#define strncasecmp strnicmp
改为:
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
就都没有问题了。我就奇怪了,为什么会出现这种问题?为什么有的时候有stricmp,而有的时候没有stricmp呢?
stricmp,_stricmp的定义在E:/Program Files/Microsoft Visual Studio 8/VC/include/string.h里面,
我们可以看到如下定义:
#if !__STDC__
....................
/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_strcmpi) _CRTIMP __checkReturn int __cdecl strcmpi(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_stricmp) _CRTIMP __checkReturn int __cdecl stricmp(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_strlwr) _CRTIMP char * __cdecl strlwr(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strnicmp) _CRTIMP __checkReturn int __cdecl strnicmp(__in_z const char * _Str1, __in_z const char * _Str, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strnset) _CRTIMP char * __cdecl strnset(__inout_ecount_z(_MaxCount) char * _Str, __in int _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strrev) _CRTIMP char * __cdecl strrev(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strset) char * __cdecl strset(__inout_z char * _Str, __in int _Val);
_CRT_NONSTDC_DEPRECATE(_strupr) _CRTIMP char * __cdecl strupr(__inout_z char * _Str);
#endif /* !__STDC__ */
从上面可以看出,如果__STDC__ 为0,则会有stricmp的定义,否则就没有。