在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的定義,否則就沒有。