How to call a third-party library file (. so) in Android NDK ).

Source: Internet
Author: User

I suffered a loss when calling third-party so files in the C ++ code of Android NDK for the first time. put the so file in the libs/armeabi directory. If you did not expect an ndk-build, the so file will be deleted and a link error will be reported. it is found that NDK is called. so needs to be PREBUILT processing, the steps are as follows:

1. Create a prebuilt subdirectory under the project/jni directory (the directory name can be customized). 2. Put the third-party. so in prebuilt and create Android. mk. The content is as follows:

LOCAL_PATH: = $ (call my-dir)

Include $ (CLEAR_VARS)

LOCAL_MODULE: = xxx

LOCAL_SRC_FILES: = libxxx. so

Include $ (PREBUILT_SHARED_LIBRARY)

3. Add the following content to project/jni/Android. mk:

LOCAL_SHARED_LIBRARIES: = xxx

4. Add it at the end of project/jni/android. mk

Include $ (LOCAL_PATH)/prebuilt/Android. mk

5. Run cygwin and run $ NDK/ndk-build static library reference under the project directory.

Two days ago, I wanted to use jni to call some ready-made code. So I used NDK to compile the project. The Android. mk file is as follows:

View plainprint?
  1. LOCAL_PATH: =$ (CallMy-dir) 
  2.   
  3. Include$ (CLEAR_VARS)  
  4.   
  5. LOCAL_MODULE   : =My_jni 
  6. LOCAL_SRC_FILES: =My_jni.c 
  7.   
  8.   
  9. LOCAL_STATIC_LIBRARIES: =Libstatic 
  10.   
  11. LOCAL_LDLIBS: =-Llog  
  12.   
  13. Include$ (BUILD_SHARED_LIBRARY) 

Libstatic. a is the third-party static library that I want to call.

However, if a problem occurs, the system prompts that the function in the static library cannot be found, as shown below:

View plainprint?
  1. D:/WJR-WorkPlace/WorkSpace/Android/jni/my_jni.c: 172:UndefinedReferenceTo'_ Destroy' 

_ Destroy is a function provided by a third-party static library.

I found a lot of information and failed to solve the problem. I finally solved the problem with the help of my colleagues because the static library link is incorrect and I changed android. mk

View plainprint?
  1. LOCAL_PATH: =$ (CallMy-dir) 
  2.   
  3. Include$ (CLEAR_VARS)  
  4. LOCAL_MODULE   : =Static 
  5. LOCAL_SRC_FILES: =Libstatic.  
  6. Include$ (PREBUILT_STATIC_LIBRARY) 
  7.   
  8. Include$ (CLEAR_VARS)  
  9.   
  10. LOCAL_MODULE   : =My_jni 
  11. LOCAL_SRC_FILES: =My_jni.c 
  12.   
  13. Local_static_libraries: =Static 
  14.   
  15. Local_ldlibs: =-Llog  
  16.   
  17. Include$ (Build_shared_library) 
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: info-contact@alibabacloud.com 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.