C++ – how to reference Math.h in Visual Studio 2015

android-ndkcvisual studio

I use this modf() but the compiler says "undefined reference to modf." I already include math.h file in the project.

I include the path to math.h in project property->General:[Additional Include Directories] which is at "C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e\platforms\android-19\arch-arm\usr\include."

I also add the linker property, Linker->Input:[Additional Dependencies] which is "libm.so" and I put the path to "libm.so" at Linker->General:[Additional Library Directories] for "C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e\platforms\android-19\arch-arm\usr\lib"

Below is the code to call modf()..

#include <math.h>
#include "MyMath.h"

double MyMath::testMod(double a, double b)
{
    return modf(a, &b);
}

What else I'm missing here? thanks.

————–Update Info——————-

I'm new to Visual Studio 2015 so this must be new feature in VS because the Error List Windows keeps switch between errors. If I click on certain source file then rebuild the project, the error will show differently based on the selected source file.

So the prior situation to the error above with math.h file, it's my project pulling math.h file in twice. It pulls from these locations:

C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e\platforms\android-19\arch-arm\usr\include

and

C:\ProgramData\Microsoft\AndroidNDK\android-ndk-r10e\platforms\android-19\arch-x86\usr\include

Notice the arch folders they are different because they are 'arch_arm' and 'arch-x86' Now i don't know why it does that. I'm just trying to build this project with NDK to use on android device so I want to build with arm.

Best Answer

You can try cmath header file instead of math.h

For more information you can refer

C++ - cmath vs math.h (And similar c-prefixed vs .h extension headers)