Using the STL with Android NDK C++
Solution 1
It seems that the mistake was a somehow broken NDK. I reinstalled it (delete, unzip) and now it works.
Solution 2
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
Related videos on Youtube
HardCoder
Updated on November 28, 2020Comments
-
HardCoder over 3 years
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 ?
-
paulsm4 about 12 yearsMy advice is to stick with the Java API. Honestly :(
-
Yury about 12 yearsMaybe stackoverflow.com/questions/4893403/… and stackoverflow.com/questions/1650963/ustl-or-stlport-for-android will help you.
-
Emile Cormier about 12 yearsWhat version of the NDK are you using?
-
HardCoder about 12 yearsI am using the NDK r7 and unfortunately none of the 2 links posted by Yury work.
-
-
Abhiram mishra about 10 yearsSorry did not work for me. The same build works fine in Linux env,but fails in Windows. Still looking for an answer.
-
Sumit Kumar Saha about 7 yearsits better to put c++_shared so as to include libcpp_shared.so in the apk