Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the STL with Android NDK C++

I am trying to use the STL in an Android NDK C++ File. I try to use map, vector and various other stl classes and I cannot compile it because it doesn't find the files.

My classes header starts with:

#pragma once
#include <map>
#include <iostream>
#include <stdexcept>
#include <vector>
#include <set>
#include <list>
#include <algorithm>

and I get following error messages:

2>  In file included from jni/../../Classes/Assist/Test.cpp:1:
2>  jni/../../Classes/Assist/Test.h:2:15: error: map: No such file or directory
2>  jni/../../Classes/Assist/Test.h:3:20: error: iostream: No such file or directory
2>  jni/../../Classes/Assist/Test.h:4:21: error: stdexcept: No such file or directory
2>  jni/../../Classes/Assist/Test.h:5:18: error: vector: No such file or directory
2>  jni/../../Classes/Assist/Test.h:6:15: error: set: No such file or directory
2>  jni/../../Classes/Assist/Test.h:7:16: error: list: No such file or directory
2>  jni/../../Classes/Assist/Test.h:8:21: error: algorithm: No such file or directory
2>  In file included from jni/../../Classes/Assist/Test.cpp:1:

I read various posts and tried "APP_STL := stlport_static" and "APP_STL := gnustl_static" in an application.mk file but it didn't work.

Does anyone know how I can get this to work ?

like image 363
HardCoder Avatar asked Feb 26 '12 23:02

HardCoder


People also ask

What can I do with Android NDK?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.

What compiler does Android NDK use?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.

Is NDK faster than Java?

the native version will usually be much faster.


2 Answers

I had the same problem, and then realized that I need to put: APP_STL := stlport_static

in Application.mk, not Android.mk ... doh

Then I needed to add: ${ANDROID_NDK_ROOT}\sources\cxx-stl\stlport\stlport

to the include paths in eclipse to make it not complain in the UI about errors

like image 68
The Dark Brainer Avatar answered Nov 02 '22 01:11

The Dark Brainer


It seems that the mistake was a somehow broken NDK. I reinstalled it (delete, unzip) and now it works.

like image 37
HardCoder Avatar answered Nov 01 '22 23:11

HardCoder