Android的NDK:load_library:无法找到函数srand函数、NDK、Android、srand

2023-09-04 05:08:49 作者:·..坚强挺过、

我有一个Android项目中,我使用本机code做的东西与SIP(使用libosip2和libeXosip2)。我的家乡code编译再加上图书馆的资源在一个模块中。

I have an android project where I use native code to do stuff with SIP (using libosip2 and libeXosip2). My native code is compiled together with the libraries' sources into one module.

在code编译就好了生成的库拥有所有我希望它有符号,但是当我尝试加载生成的图书馆中,我得到以下错误:

The code compiles just fine and the generated library has all the symbols I expect it to have, but when I try to load the generated library I get the following error:

E/eXosip.loadLibrary(9210): java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1307]:  1941 cannot locate 'srand'...

我的Application.mk看起来是这样的:

My Application.mk looks like this:

APP_STL         := gnustl_shared
APP_ABI         := armeabi-v7a
APP_CPPFLAGS    += -fexceptions

我没有检查未捕获的依赖性使用NDK-依赖,这给了我

I did check for uncaught dependencies using ndk-depends, which gives me

libeXosip_jni.so
libstdc++.so
liblog.so
libgnustl_shared.so
libm.so
libdl.so
libc.so

添加一个调用LoadLibrary(gnustl_shared)没有帮助(这是提到库还发现,在库中唯一一个/ armeabi-V7 /").

Adding a loadLibrary("gnustl_shared") does not help (which is the only one of the mentioned libraries also found in "libs/armeabi-v7/").

我的Andr​​oid.mk:

My Android.mk:

LOCAL_PATH  := $(call my-dir)
$(shell (cd $(LOCAL_PATH); sh extract_stuff.sh; cd $(OLDPWD)))


include $(CLEAR_VARS)
OSIP        := libosip2-4.1.0
EXOSIP      := libeXosip2-4.1.0
LOCAL_MODULE    := eXosip

LOCAL_C_INCLUDES    := $(LOCAL_PATH)/$(OSIP)/include \
                       $(LOCAL_PATH)/$(EXOSIP)/include

LOCAL_SRC_FILES := $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(OSIP)/src/osipparser2/*.c)) \
                   $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(OSIP)/src/osip2/*.c)) \
                   $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(EXOSIP)/src/*.c))

LOCAL_CFLAGS += -DHAVE_FCNTL_H \
                -DHAVE_SYS_TIME_H \
                -DHAVE_STRUCT_TIMEVAL \
                -DHAVE_SYS_SELECT_H \
                -DHAVE_PTHREAD \
                -DHAVE_SEMAPHORE_H \
                -DENABLE_TRACE \
                -DOSIP_MT

include $(BUILD_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE    := eXosip_jni
LOCAL_STATIC_LIBRARIES  := eXosip
LOCAL_LDLIBS := -llog 

LOCAL_C_INCLUDES := BackendData.h \
                    $(LOCAL_PATH)/$(EXOSIP)/include \
                    $(LOCAL_PATH)/$(OSIP)/include

LOCAL_SRC_FILES := eXosip.cpp \
                   eXosipCall.cpp

include $(BUILD_SHARED_LIBRARY)

C / C ++是不是我的刚毅,因此,如果有人可以开导我,我会非常感激:)作为替代方案,解决我的问题,也将是不错的^^

C/C++ is not my fortitude, so if someone could enlighten me I'd be really grateful :) As an alternative, a solution to my problem would also be nice ^^

更新1

我分开了eXosip /约瑟夫库从我的code,编译成静态库。我还测试创建共享库和Java里面加载的手时,出现相同的错误消息。

I separated the eXosip/osip library from my code, compiling it into a static library. I also tested creating a shared library and loading it by hand from inside Java, it fails with the same error message.

更新2

我试着用gnustl_shared,静也STLport的 - 错误仍然

I tried using gnustl_shared, static and also stlport - the error remains.

推荐答案

感谢Chris我意识到我的错误,这是使用的 NDK用于64位器件的。虽然使用的是最小的例子,我不能复制错误(这似乎是特定于libosip2可能还有其他),使用32位NDK 解决了问题。

Thanks to Chris I realized my mistake, which was using the NDK intended for 64bit devices. Though I could not replicate the error using a minimal example (it seems to be specific to libosip2 and possibly others), using the 32bit NDK resolved the issue.

谢谢大家谁花时间发表评论,并提出建议后!

Thank you everyone who took the time to comment and post suggestions!