2

I am trying to build a C program which was originally built on Linux with gcc -lm ... option, which uses the math library while linking the code. How can use the same in project settings of a Visual Studio 2005 compiler, on Win32 environment?

EDIT: Basically the original Linux code includes math.h and uses gcc -lm to link the math library. But when I use this in Windows, I get a compilation error: NAN :- undeclared identifier.

I am looking to resolve this.

eh9
  • 7,340
  • 20
  • 43
goldenmean
  • 18,376
  • 54
  • 154
  • 211

1 Answers1

0

Visual C++ 2005 does not contain a definition for NAN. You can define it like this:

#ifdef WIN32
    #ifndef NAN
        static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
        #define NAN (*(const float *) __nan)
    #endif
#endif

(I got the code from this blog post by Tom Distler. Thanks Tom.)

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72