5

Background: I'm dealing with some legacy systems on msvc9, and there are problems with floating point to int conversions. It emits a __ftol2_sse instruction which is an undefined reference if not compiling for SSE.

The only way to suppress this is with the /QIfist option which performs the conversion inline, without calls to any ftol(). However, those inline conversions have a different rounding algorithm, and thus cause problems when used with the existing code. That, and they emit unsuppressible 'deprecated' warnings to cl.exe stderr.

The workaround I have is:

// Declare a regular _ftol() function that is present.
long __cdecl _ftol(double); 
// Define _ftol2_sse() to be the regular one.
long __cdecl _ftol2_sse(double f) { return _ftol(f); }

And that works nicely. However, some builds do have _ftol2_sse defined, in which case I get multiple definitions, and it's a pain to figure that out in the code.


I was hoping to do something like --wrap __ftol2_sse from ld, and just override the behavior on all builds. Is anything like this possible on MSVC?

mtijanic
  • 2,792
  • 10
  • 25
  • Just put it in a .lib, link it last. – Hans Passant Aug 14 '15 at 17:38
  • 1
    @HansPassant But if a default implementation is already provided, it will report multiple definitions. I don't think MSVC has a way to define weak symbols. Does it? – mtijanic Aug 14 '15 at 18:08
  • 2
    Sort of. The undocumented [`/ALTERNATENAME`](https://stackoverflow.com/a/11529277) linker option. – cremno Aug 14 '15 at 19:00
  • @cremno According to your link, it seems the `/ALTERNATENAME` can only work **if there's no definition present yet**. If the function is already defined, maybe it cannot be replaced. Anyway, I didn't try it, just some literal deduction. According to here (https://ofekshilon.com/2014/02/10/linker-weak-symbols/), "*it is hardly a replacement*". – smwikipedia Nov 27 '19 at 08:22

0 Answers0