2012년 1월 2일 월요일

Import STL libraries to the Android NDK code

출처 : http://www.41post.com/3527/programming/import-stl-libraries-to-android-ndk-code


Import STL libraries to the Android NDK code

Import STL libraries to the Android NDK code thumbnail
This is a quick tip for those who are beginning to write native Android code. As one may have noticed, it isn’t possible to use containers like,stringvectorlist inside the NDK samples. These are all part of the STL(Standard Template Library), and are expected to be available when writing C++ code.
To add STL to your NDK code, locate the Application.mk file inside your project’s jni folder. If it isn’t there, create it. Please note that the Application.mk is not theAndroid.mk file! The Android.mk file instructs the compiler and the JNI on how NDK code should be handled. The Application.mk, works similarly as the Android manifest file for your NDK code, allowing the programmer to add permissions and define other applications’ properties, like such as ‘enabling’ the STL support.
After creating the Application.mk, add this line of code:
  1. APP_STL := stlport_static  
Now at the .c or .cpp file or at the header of the class where STL needs to be included, add the following:
  1. //to use strings  
  2. #include <string>  
  3.   
  4. //to use vectors  
  5. #include <vector>  
  6.   
  7. //and so on...  
  8.   
  9. /* add this line, to avoiding writing 'std::' every time a string (or any 
  10. other container) is declared.*/  
  11. using namespace std;  
This was tested using Android NDK, Revision 5b, released in January 2011. I don’t know if works on previous version of the NDK.

댓글 없음:

댓글 쓰기