views:

2929

answers:

4

I'm using a fairly new install of Visual C++ 2008 Express.

I'm trying to compile a program that uses the log2 function, which was found by including using Eclipse on a Mac, but this Windows computer can't find the function (error C3861: 'log2': identifier not found).

The way I understood it, include directories are specific to the IDE, right? math.h is not present in my Microsoft SDKs\Windows\v6.0A\Include\ directory, but I did find a math.h in this directory: Microsoft Visual Studio 9.0\VC\include. There is also a cmath in that directory...

Where is log2?

+9  A: 

From here:

Prototype: double log2(double anumber);
Header File: math.h (C) or cmath (C++)

Alternatively emulate it like here

#include <math.h>  
...  
// Calculates log2 of number.  
double Log2( double n )  
{  
    // log(n)/log(2) is log2.  
    return log( n ) / log( 2 );  
}

Unfortunately Microsoft does not provide it.

lothar
+3  A: 

Evidently Microsoft didn't think it was worth including.

http://msdn.microsoft.com/en-us/library/7wsh95e5(VS.80).aspx

Lothar has the right idea.

Mark Ransom
Yep - it was on my Mac but not the PC... strange.
Tony R
A: 

I am trying to help on your issue: making this program compile under windows (isn't it what you are trying to do ?).

Did you try to include the math.h header file at the begining of your file ? (if not so , maybe the compiler you were using under mac os was including this file automatically, and if the compiler you are using under winsows os won't ... )

Does your project configuration needs to explicitly declare that you are using standard header file ? Or to tell all path where to find header files you will include in your project?

I hope it will help you ...

yves Baumes
+1  A: 

log2() is only defined in the C99 standard, not the C90 standard. Microsoft Visual C++ is not fully C99 compliant (heck, there isn't a single fully C99 compliant compiler in existence, I believe -- not even GCC fully supports it), so it's not required to provide log2().

Adam Rosenfield