2

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.

Eteru
  • 21
  • 3

2 Answers2

0

If you #include <cmath> The methods are in std namespace so you should use std::acos etc.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • When I include there's an error for every cmath function with `no member named 'function' in the global namespace`. In the header file there are some `using ::function` declarations. – Eteru Jan 07 '18 at 15:37
-1

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.

Eteru
  • 21
  • 3
  • hi, I am having the same issue, would you be able to provide some guidance? – Roman Rekhler Oct 17 '18 at 13:43
  • If i remember correctly, the issue was that i was starting from an "OpenGLES Application" which is for both Android and iOS. I'm not entirely sure what the issue was, but if you create a "Native-Activity Application" (New Project > Visual C++ > Cross Platform > Android) it should work. Also remember that from that point forward to treat your code like you're writing for Linux (Android). – Eteru Oct 18 '18 at 08:26
  • Unfortunately this does not work for all functions. While the sqrt function works, the clang and gcc compiler quits with error code 1 when I try to use the pow function. – SOUser Apr 30 '19 at 06:15