问题
I'm trying to port some OpenGL ES code from windows to Android using the Android NDK. I'm using Visual Studio 2017 and C++. What I did so far, I created a cross platform gles project in VS and removed the ios data. I'm putting one code file after the other and try to fix any errors I can find.
The issue I have is that is seems that math.h
functions can't be found.
Here's some information that might be relevant:
- Platform toolset is clang 3.8
- Target API Level is android-21
- Language standard is c++11
- I have added
m;
as an option to linker library dependencies
If i include math.h
I get:
use of undeclared identifier 'sqrt' (and all the other math.h functions I'm using)
If i include cmath
I get:
no member names 'acos' in the global namespace (and all the other cmath functions)
Path for files (as found by Visual Studio):
c:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b\platforms\android-21\arch-x86\usr\include\math.h
c:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r13b\sources\cxx-stl\gnu-libstdc++\4.9\include\cmath
If I remove all math calls, it compiles.
Has anyone managed to use cmath in this context? If so, do you have any tips or point to what am I doing wrong?
Thanks.
回答1:
If you #include <cmath>
The methods are in std
namespace so you should use std::acos
etc.
回答2:
I have not found a fix to the questions, but creating a project from the native android template allows you to use cmath
without error, but you do need to add m;
in linker input.
来源:https://stackoverflow.com/questions/48137308/visual-studio-2017-android-ndk-math-h