Unauthorized external character "_hypot" when using the static library

I'm trying to recompile my old game that 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 to find the source code of this library and rebuild it?

I am using Visual Studio 2010 and the latest version of the DirectX SDK.

+5
source share
4 answers

. -, , ( VS 2010) , _hypot. math.h , . , , , , . , , . :

  • math.h ifdef .
  • "C" extern (double x, double y) {return _hypot (x, y);}
  • Relink

, .

+4

MT-STATIC. , (Code Generation- > Runtime Library) , DLL. , MT-DLL. , (MT MTD) , .

http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.80).aspx

+1

, , math.h.

, " msvcrt-ruby18-static.lib" DLL Visual Studio 2012 (VS2012). :

'unresolved external symbol __imp__hypot referenced in function _math_hypot'

, , " math.h".

:

double hypot(double _X, double _Y)

vs2010 dll, :

extern "C" __declspec(dllexport) double __cdecl hypot(...)

vs2010, :

static __inline double __CRTDECL hypot(...)

, VS2012 RC_INVOKED. , :

#define RC_INVOKED
#include <ruby.h>

extern "C" __declspec(dllexport)
double hypot(double x, double y)
{
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    if (x < y) {
        double tmp = x;
        x = y; y = tmp;
    }
    if (y == 0.0) return x;
    y /= x;
    return x * sqrt(1.0+y*y);
}

[ NOTICE ] My project is a DLL, and I use the dllexport keyword directly. It seems the prefix ' __ imp __ ' cannot be defined directly. I tried to define a function called __ imp__hypot (...) and I failed.

+1
source

Bring hypot()yourself in. It is pretty simple:

double hypot(double x, double y) {
    double ax = fabs(x), ay = fabs(y);
    double xy = x/y, yx = y/x;
    return ax > ay
        ? ax * sqrt(1.0 + yx*yx)
        : ay * sqrt(1.0 + xy*xy);
}
0
source

All Articles