1

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 hold of curl.h in my c code inside JNI.

Here's my Android.mk file:

LOCAL_PATH:= $(call my-dir)

LIBS_PATH := libs/$(TARGET_ARCH_ABI)

include $(CLEAR_VARS)
LOCAL_MODULE := libcurl                     
LOCAL_SRC_FILES := $(LIBS_PATH)/libcurl.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := testLib
LOCAL_SRC_FILES := lib.c

LOCAL_SHARED_LIBRARIES += libcurl

include $(BUILD_SHARED_LIBRARY)

Here's my c class:

#include "curl/curl.h"
#include "lib.h"

JNIEXPORT jint JNICALL Java_com_example_test_1libcurlandroidlib_Lib_getTestNumber
  (JNIEnv *env , jclass clazz)
{
    return 99;
}

The issue is with the "curl/curl.h" include command. I have also tried as but it does not find it either:

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

I have my libcurl.so file inside a lib folder inside the JNI folder, which at build time generates the same (I think) file into the libs folder at the root of the app:

enter image description here

Does anyone have any idea why I am not able to get a referece to curl.h, or what I have to do to get a hold of this library?

Thank you!

TooManyEduardos
  • 4,206
  • 7
  • 35
  • 66
  • Are you serious? This is a duplicate of your own question: http://stackoverflow.com/questions/28633243/how-to-import-the-curl-built-library-into-android-ndk. I already tried helping you before. – Jared Burrows Feb 24 '15 at 20:02
  • I'm voting to close this question as off-topic because this question was already asked by the same user here: http://stackoverflow.com/questions/28633243/how-to-import-the-curl-built-library-into-android-ndk. Also, I tried walking through step by step with the user. – Jared Burrows Feb 24 '15 at 20:03
  • @JaredBurrows - you managed drag the other question on quite a tangent by not paying attention to what the user was asking. **This one is far more specific about what they are doing, and gives an error message for which specific assistance can be provided.** – Chris Stratton Feb 25 '15 at 12:47
  • @ChrisStratton You managed to waste more time following this and I am glad you *actually* posted an answer this time. I was more than glad to help him walk through this issue but he stopped replying. – Jared Burrows Feb 25 '15 at 15:22

1 Answers1

0

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.

Community
  • 1
  • 1
Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Thanks Chris. One question: should the includes of "LOCAL_C_INCLUDES := curlibrary/include" be in the Android.mk of the library generating the .so files, or should it be in the project that is trying to use the .so files? – TooManyEduardos Feb 25 '15 at 15:28
  • Include paths specify where to find something you need, so it belongs in the user. If you are building the library it will probably need the same or similar header files, though you would have to look at the setup of the particular build system to see how they are supposed to be found. – Chris Stratton Feb 25 '15 at 15:50
  • Thanks Chris, I'll chase it that way – TooManyEduardos Feb 25 '15 at 16:10
  • @TooManyEduardos Does it worked for you? I'm working in a similar case, without success till now, I'm not able to include my libcurl.so to my C++ code (Getting the same error) – Mauricio Sartori Jul 06 '15 at 09:13