avoid using of .a for creation of .so

时光毁灭记忆、已成空白 提交于 2019-12-24 18:40:31

问题


i have created an android application,here most of my code is in c so i have created it using jni. i have to create socket.so file, in which i have to use the libtest.so.

while using the libtest.so in socket.so i get the error:undefined reference to function(). my function() is present inside the libtest.so. so to avid this by suggestion i have created my Android.mk as below:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libtest
LOCAL_SRC_FILES := libtest.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := socket
LOCAL_SHARED_LIBRARIES += libtest
LOCAL_SRC_FILES := source/interface.c source/file.c
LOCAL_LDFLAGS += libtest.a  
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../libtest/jni/include
include $(BUILD_SHARED_LIBRARY)

but it requires both the libtest.so & libtest.a file to be present. where as if i am using only the libtest.a it works perfectly fine.

since my requirement is to create libtest.so and include it in socket.so can any one please tell me how to avoid dependency of .a file to create .so file.

if i will comment LOCAL_LDFLAGS += libtest.a then i am getting the error:undefined reference to function()

any one plz help me to get out of this problem.......


回答1:


Seems a bit unclean.

The shared library (.so) and the archive (.a) are both supposed to contain the same code, but in practice they might not. The first thing you should do is check if the .so really has all the symbols. The linker might have optimized some out. Use the nm utility or objdump for that purpose.

Can you also post a console dump of the commands ndk-build is executing?

You might also try to avoid what you're doing, as the NDK is not really meant to produce shared libraries that depend on each other. It's possible of course, but the recommended approach is to stuff your libs into static archives and link them directly into the resulting JNI .so.

Edit:

LOCAL_SRC_FILES := libtest.so seems wrong. If you want to link with a shared library, pass the library to the linker not the compiler: LOCAL_LDFLAGS += libtest.so or, even better, LOCAL_LDFLAGS += -L. -ltest




回答2:


thanks alot to @onitake.

there was a simple mistake over here was that the libtest.so was not proper(created by code having bugs).

then when i have created a proper libtest.so,

Note:

if some one is having proper .so file and still it gives error then there might be some linking error. So jst remove the line:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../libtest/jni/include

and put

LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/../../libtest/jni/include 

both of above statements are same but some times it's work.



来源:https://stackoverflow.com/questions/11686265/avoid-using-of-a-for-creation-of-so

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!