Android NDK use .so library from c code inside JNI

前端 未结 1 775
北恋
北恋 2021-01-16 08:06

I found similar questions on SO but none of them were with the same workflow.

I have a .so library (libcurl) in my project. The project builds but I need to get a ho

相关标签:
1条回答
  • 2021-01-16 08:27

    jni/lib.c:2:23: fatal error: curl/curl.h: No such file or directory

    include "curl/curl.h"

    To make use of this library, you need not only the compiled .so file, but also a set of function prototypes (and perhaps data type definitions) customarily provided by a header file.

    With a well-defined library installation, these would be provided in a path adjacent to the binary - ie, you would have some "curlibrary/lib/libcurl.so" and next to it a "curlibrary/include/curl/curl.h"

    To make that work, you would add the path of curl's include directory to your compiler command line, presumably by adding it to your Android.mk

    LOCAL_C_INCLUDES := curlibrary/include
    

    Or wherever you are keeping it.

    To make use of the include path, your references to the library in code need to be enclosed in angle brackets, not double quotes, ie

    #include <curl/curl.h>  //this searches the include path
    

    instead of

    #include "curl/curl.h"  //while this specifies a location relative to this source file
    

    In a more fly-by-night context you may not really have a well-defined installation, but simply a .so file (hopefully compatible with your Android ABI) that you want to use, and a header file that you have either extracted or even re-created. In that case, you might more haphazardly toss "curl.h" somewhere in your project source, and include it via a specific quoted path as you were trying to do. Provided that path is correct, it will work - but it breaks the clean hierarchy of design, and could cause confusion if the api of curl ever changes in the future.

    0 讨论(0)
提交回复
热议问题