Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unresolved external symbol "_hypot" when using static library

I'm trying to recompile my old game which links the Ruby library, but I keep getting this error:

ruby18-mt-static-release.lib(math.obj): error LNK2001: unresolved external symbol _hypot

Is there any workaround for this that doesn't require me finding the source code to this library and rebuilding it?

I'm using Visual Studio 2010 and the latest DirectX SDK.

like image 331
zaratustra Avatar asked Jul 24 '11 19:07

zaratustra


1 Answers

I had a similar problem. Apparently hypot used to be a linkable function but is now (I have VS 2010) an inline function that calls _hypot. In math.h this is the only function where this is done. I don't have source for the existing library I am using and it has hypot linked to it so it can't use the inline version. If I just define hypot myself the linker says it is already defined. The following works to fix this:

  • Edit math.h and comment or ifdef out the inline version of hypot.
  • Implement hypot as extern "C" double hypot(double x, double y) {return _hypot(x, y);}
  • Relink

Ugly, but it solved the problem.

like image 194
Matt Morrise Avatar answered Oct 18 '22 07:10

Matt Morrise