Recent

Author Topic: Undefined symbol: __ms_vsnprintf when linking with C code  (Read 10439 times)

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1170
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #15 on: January 22, 2017, 01:28:49 pm »
The following might or might not help.

When trying to static include sqlite3 into the mORMot on win64, a crash happened during init when sqlite3 was compilied with optimalization level >=2 (with gcc).
Going back to 1 or 0 did solve the crash.
Again, it might help. Or not.
And I do not know if you are able to recompile your lib.

I think it has to do with thread init. But I have not tracked it down till now.

alex256

  • New Member
  • *
  • Posts: 24
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #16 on: January 22, 2017, 05:38:55 pm »
The following might or might not help.

When trying to static include sqlite3 into the mORMot on win64, a crash happened during init when sqlite3 was compilied with optimalization level >=2 (with gcc).
Going back to 1 or 0 did solve the crash.
Again, it might help. Or not.
And I do not know if you are able to recompile your lib.

I think it has to do with thread init. But I have not tracked it down till now.

I'm able to recompile my library, but I compiled it without any optimizations.

Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #17 on: January 22, 2017, 06:35:46 pm »
Try adding
Code: Pascal  [Select]
  1. {$ifdef win64}
  2.  var
  3.     __ms_vsnprintf:pointer = nil;
  4. {$endif}
  5.  
before the {$linklib}'s

The actual function prototype is __ms_vsnprintf = function(s:Pchar; n:size_t; const format:Pchar):integer;varargs;stdcall;
« Last Edit: January 22, 2017, 07:36:37 pm by Thaddy »
also related to equus asinus.

alex256

  • New Member
  • *
  • Posts: 24
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #18 on: January 22, 2017, 06:51:04 pm »
Try adding
Code: Pascal  [Select]
  1. {$ifdef win64}
  2.  var
  3.     __ms_vsnprintf:pointer;
  4. {$endif}
  5.  
before the {$linklib}'s

It doesn't work  :( The same linker error.

Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #19 on: January 22, 2017, 07:42:42 pm »
Next trick. Let's force it to be defined.
Compile this and Link this before any other library and see what happens.
Code: Pascal  [Select]
  1. library vp;
  2. // For WIN64 only, otherwise cdecl
  3. uses unixtype;
  4. type
  5.     Tvsnprintf = function(s:Pchar; n:size_t; const format{array of char}):integer;varargs;stdcall; //win64 has no cdecl!, just stdcall (or a winapi macro to stdcall)
  6. var
  7.   __ms_vsnprintf:Tvsnprintf = nil;export;
  8. begin
  9. end.
  10.  

That should solve the linker issue, but of course the function can not be called.
I suspect it is in msvcrt.dll or in the proprietary safestring library. by MS. (That's not a dll but a static library, it comes with the SDK, however and also with all versions of visual studio including the community edition)
« Last Edit: January 22, 2017, 08:04:10 pm by Thaddy »
also related to equus asinus.

alex256

  • New Member
  • *
  • Posts: 24
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #20 on: January 23, 2017, 05:23:40 pm »
I did this, but when I run my program, I get error 0xc000007b.  :(

I'll better try to link my C library dynamically with the program...

alex256

  • New Member
  • *
  • Posts: 24
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #21 on: January 23, 2017, 05:33:07 pm »
I put my C code in DLL and it works!  :)


Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #22 on: January 23, 2017, 06:13:24 pm »
Good!.
Funny thing is  discovered that MY version of Cygwin64 AND Mingw64 both contain this  __ms_vsnprintf routine in the includes and libraries, so there may still be something wrong with your setup? (Is is properly declared as external in your Pascalcode?)  OTOH if it works leave it alone  O:-) There's more MS code that only seems to works from a dll anyway.
« Last Edit: January 23, 2017, 06:17:22 pm by Thaddy »
also related to equus asinus.

alex256

  • New Member
  • *
  • Posts: 24
Re: Undefined symbol: __ms_vsnprintf when linking with C code
« Reply #23 on: January 23, 2017, 06:58:17 pm »
Good!.
Funny thing is  discovered that MY version of Cygwin64 AND Mingw64 both contain this  __ms_vsnprintf routine in the includes and libraries, so there may still be something wrong with your setup? (Is is properly declared as external in your Pascalcode?)  OTOH if it works leave it alone  O:-) There's more MS code that only seems to works from a dll anyway.

What installation do you use?