Problems and Solutions for using C ++ In the android JNI Environment

Source: Internet
Author: User

When testing the availability of the tinythread ++ library on different mobile platforms, several problems were encountered. Tinythread ++ is known as a thread library compatible with the c ++ 11 standard. It can be used when C ++ 11 is unavailable. In the future, C ++ 11 will become more popular and can be easily replaced.

Test status on different platforms:

  • IOS: Pass. You need to rename the. M file that calls the C ++ code to the. MM file.
  • WP: unknown. Not involved.
  • Android: Pass. After solving the following problems.
C ++ problems in the android JNI environment:1) Error: Base operand of '-> 'has non-pointer type' _ jnienv'

The calling method of C ++ is different from that of C. Comparison:

C++:  env->NewStringUTF("JNI C++!");  C:  (*env)->NewStringUTF(env, "JNI C!");


jstringJava_com_listthrd_MainActivity_runListThrd( JNIEnv* env,                                                  jobject thiz ){  // for C++  return env->NewStringUTF("JNI C++!");  // for C//  return (*env)->NewStringUTF(env, "JNI C!");}
2) error: iostream: no such file or directory

STL library files such as iostream cannot be found, because STL is not used by ndk by default. Solution:
Create the application. mk file in the JNI directory and add the following content:

#APP_STL:=stlport_staticAPP_STL := gnustl_static

Select either of the preceding two. Gnustl is recommended because it can solve other problems. See later.
3) error: 'terminate' is not a member of 'std'

This error occurs when stlport is used. Use gnustl_static instead.
4) undefined reference to '_ cxa_end_cleanup'

This error occurs when stlport is used. Therefore, use gnustl_static instead.
5) undefined reference to '_ android_log_print'

This is a log library that is not linked to Android. Add the local_ldlibs definition to the Android. mk file as follows:


Above, local_export_ldlibs is easy to use in C language, which can be removed here.
6) Error/androidruntime (330): Fatal exception: Main
Java. Lang. unsatisfiedlinkerror...

Use the C language-style call convention to add extern before the exported JNI Function
"C" is specified, or the JNI export function is enclosed by curly arc. For example:

extern "C" {  JNIEXPORT jstring JNICALL  Java_com_listthrd_MainActivity_runListThrd( JNIEnv* env, jobject thiz )  {    // ...  }}

1. tinythread ++:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.