ui icon indicating copy to clipboard operation
ui copied to clipboard

Compile error ( error: 'vsprintf_s' was not declared in this scope )

Open Lintfy opened this issue 7 years ago • 4 comments

I tried to compile "controllgallery2.nim" , but ..

Error: execution of an external compiler program 'gcc.exe -c -w -mno-ms-bitfields -IC:\Users\(User name)\Documents\Language\Nim\nim-0.18.0\lib -o G:\Nim \nimcache\win_debug.cpp.obj C:\Users\(User name)\.nimble\pkgs\ui-0.9.2\ui\./libui/windows\debug.cpp' failed with exit code: 1 C:\Users\terur\.nimble\pkgs\ui-0.9.2\ui\./libui/windows\debug.cpp: In function 'void realbug(const char*, const char*, const char*, const char*, con st char*, va_list)': C:\Users\(User name)\.nimble\pkgs\ui-0.9.2\ui\./libui/windows\debug.cpp:76:31: error: 'vsprintf_s' was not declared in this scope vsprintf_s(msg, n, format, ap); ^

What I should do to fix that error? (Sorry for my poor English..)

Lintfy avatar Jun 30 '18 11:06 Lintfy

Pretty sure this is an issue with libui:

https://github.com/andlabs/libui/issues/259

haltcase avatar Aug 20 '18 22:08 haltcase

The root as I understand it is that vsprintf_s is a more secure version of the original vsprintf but it's a Microsoft extension only present in vcc, meaning it fails to compile with gcc/mingw. You can monkey patch this to fix it locally:

  1. Go wherever you have nimble installing your packages

    Windows default: C:\Users\<USER>\.nimble\pkgs Unix default: ~/.nimble/pkgs

  2. Go to ui-<version>\ui\libui\windows

  3. Open debug.cpp and comment out line 76:

    -vsprintf_s(msg, n, format, ap);
    +// vsprintf_s(msg, n, format, ap);
    

This will solve that error, but there are more of these in libui:

  • utf16.cpp:59 wcscpy_s
  • utf16.cpp:90 vswprintf_s

haltcase avatar Aug 21 '18 15:08 haltcase

This is still happening, libui issue is closed as resolved: https://github.com/andlabs/libui/issues/259

kidandcat avatar Jul 05 '19 07:07 kidandcat

@kidandcat it doesn't appear to be closed yet per the issue status and the latest comment from the dev. The safe string functions mentioned here will still likely cause these errors.

haltcase avatar Jul 05 '19 15:07 haltcase