> From: Dongsheng Song [mailto:dongsheng.s...@gmail.com] > Sent: Tuesday, March 08, 2011 5:56 PM > To: Dock, Dion > Cc: mingw-w64-public@lists.sourceforge.net > Subject: Re: [Mingw-w64-public] why aren't "secure" _s functions provided? > > On Wed, Mar 9, 2011 at 03:32, Dock, Dion <dion_d...@mentor.com> wrote: > > I'm back to my original question: can I use MinGW64 with source that has > functions like strnlen_s? > > It sounds like the answer is: I can compile code with those functions in a > DLL with a manifest for msvcr80 (or 90 or 100) or statically link the runtime > into that > DLL. However, I cannot compile code with those functions using > MinGW64. > > Or to put it another way, how would you get this to compile with MinGW64? > #include <stdio.h> > #include <string.h> > > int main() > { > printf("%d\n", strnlen_s("foo", 2)); /* expect 2 */ > return 0; > } > > Here's what I get: > C:\Temp>C:\mingw_32\bin\i686-w64-mingw32-gcc.exe main.c > C:\Users\dockd\AppData\Local\Temp\ccKqFt47.o:main.c:(.text+0x1e): undefined > reference to `strnlen_s' > collect2: ld returned 1 exit status > > -Dion > > It seems that you can compile your program, so you can copy msvcr100.dll to > libmsvcrt.a, it should works fine. > Or link with: gcc test.c -lmsvcr100 > > But I checked the functions in msvcr100.dll, no strnlen_s, only have the > following string functions: > > strcat_s > strcpy_s > _strdate_s > _strerror_s > strerror_s > _strlwr_s > strncat_s > strncpy_s > _strnset_s > _strset_s > _strtime_s > strtok_s > _strupr_s
How did you do that? nm isn't displaying those functions in my preferred runtime lib, libmsvcr80.a. For example, C:\Temp>C:\mingw_32\bin\i686-w64-mingw32-nm.exe C:\mingw_32\mingw\lib\libmsvcr80.a | find "strcpy_s" C:\Temp> > > When I check VC 10, I found it's a inline function: > > #if __STDC_WANT_SECURE_LIB__ && !defined (__midl) > _Check_return_ static __inline size_t __CRTDECL strnlen_s(_In_z_ const char > * _Str, _In_ size_t _MaxCount) > { > return (_Str==0) ? 0 : strnlen(_Str, _MaxCount); > } > > _Check_return_ static __inline size_t __CRTDECL wcsnlen_s(_In_z_ const > wchar_t * _Src, _In_ size_t _MaxCount) > { > return (_Src == NULL) ? 0 : wcsnlen(_Src, _MaxCount); > } > #endif > > So if you want use "secure" _s functions, you can link with -lmsvcr100, but > please do not use strnlen_s/wcsnlen_s, > or you must define your self. > > -- > Dongsheng Thanks! Adding the "-lmsvcr80" resolved a few of the symbols. Now I've hit the next stumbling block: vsnprintf_s and localtime32_s. These don't seem to be in libmsvcr80.a, but per the above, I'm not sure how to check for their presence. Neither is a macro, however. -Dion ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public