避免创建使用.A的。所以 [英] avoid using of .a for creation of .so

查看:145
本文介绍了避免创建使用.A的。所以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Android应用程序,在这里我的大部分code是在C,所以我必须使用JNI创建它。我要创建 socket.so 文件,在其中我必须使用 libtest.so

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.

在使用 libtest.so 在socket.so我得到的错误:未定义引用函数() 。我()函数是在 libtest.so present。因此通过建议,废寝忘食这个我已经创造了我的Andr​​oid.mk如下:

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)

但它同时需要 libtest.so &安培; libtest.a 文件是present。在那里,如果我使用仅 libtest.a 这工作完全正常。

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.

因为我的要求是创建libtest.so,并将其纳入socket.so任何一个可以请告诉我如何避免某文件的依赖性创建.so文件。

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.

如果我会评论 LOCAL_LDFLAGS + = libtest.a 然后我收到错误:未定义引用函数()

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

任何一个plz帮助我走出这个问题.......

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

推荐答案

似乎有点不干净。

共享库(的.so)和归档(.a)都应该包含在同一code,但在实践中,他们可能不会。你应该做的第一件事就是检查。所以真的有所有的符号。链接器可能已经优化了一些列。使用纳米工具或 objdump的用于这一目的。

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.

你能还发布命令的控制台转储NDK的构建正在执行?

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

您也可以尽量避免自己在做什么,因为NDK是不是真的意味着产生互相依赖的共享库。这是可能的,当然,但建议的方法是你的东西到库的静态档案和直接链接到它们所产生的JNI的.so。

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.

编辑:

LOCAL_SRC_FILES:= libtest.so 似乎是错误的。如果你想的链接的一个共享库,该库传给连接器不是编译器: LOCAL_LDFLAGS + = libtest.so ,或者甚至更好, LOCAL_LDFLAGS + = -L。 -ltest

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

这篇关于避免创建使用.A的。所以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆