1

I have come across a problem with trying to compile cURL with SSL support into an app.

So far, I have successfully compiled the openSSL package into libcrypt.so and libssl.so.

I believe I have successfully compiled a version of libcurl.a with SSL support using the configure script and running it through the cross-chain compiler found in the NDK (under a linux environment).

Now, I am attempting to write a .so library under Eclipse that can be called by the Java code of an Android App.

Here is the file structure so far:

Project Folder ---> jni ---> include ---> curl ---> curl headers
                         |            |
                         |             -> openssl ---> ssl and crypto headers
                         |
                          -> libcrypto.so
                          -> libssl.so
                          -> libcurl.a
                          -> jniProcessRequest.c
                          -> Android.mk

Android.mk reads:

LOCAL_PATH := $(call my-dir)
MY_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_PATH)

LOCAL_MODULE := crypto
LOCAL_SRC_FILES := libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/openssl/
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := libssl.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/openssl/
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := curl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/curl/
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := JNIProcessRequest
LOCAL_SRC_FILES := JNIProcessRequest.c
LOCAL_SHARED_LIBRARIES := crypto ssl
LOCAL_STATIC_LIBRARIES := curl
LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

jniProcessRequest.c:

#include <jni.h>
#include <stdlib.h>
#include "include/curl/curl.h"
#include <android/log.h>

JNIEXPORT void JNICALL Java_com_example_jniprocessrequest_MainActivity_jniProcessRequest(JNIEnv * env, jobject obje){
CURL *conn;
conn = curl_easy_init();
}

Every time I attempt to compile the above, I have undefined reference errors in Eclipse:

make: *** [obj/local/armeabi/libJNIProcessRequest.so] Error 1
undefined reference to 'curl_easy_init'

I am thinking this is some sort of linkage error but am struggling to find where the error is occurring. I have spent nearly two days trying all different methods of placing the shared libraries in differing places, switching the static libcurl with a shared libcurl, altering the Android.mk file and following tutorials on how to get cURL working in Android.

Any help would be greatly appreciated!

4

2 回答 2

2

我相信这个问题源于一个错误构建的 libcurl.a 静态库。我用 GitHub 上的用户编译的库替换了我的库,并且没有更改任何代码,链接错误消失了。

于 2013-11-06T00:38:27.043 回答
0

curl用作预建模块。

正如 NDK 文档所述,您应该注意将其包装在include $(CLEAR_VARS)和(最重要的)include $(PREBUILT_STATIC_LIBRARY)指令下,如下所示:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := libfoo.a
include $(PREBUILT_STATIC_LIBRARY)

之后注意用and包裹你的JNIProcessRequest模块。include $(CLEAR_VARS)include $(BUILD_SHARED_LIBRARY)

有关更多详细信息,请参阅docs/PREBUILTS.html您可以在 Android NDK 文件夹中找到的部分(如下所示)。

于 2013-11-05T08:39:11.387 回答