Android NDK linking problems

此生再无相见时 提交于 2019-12-12 03:03:53

问题


I compiled Sox et al with NDK. So, I have all Android-friendly shared libs.

I made a simple test file which calls a sox function. NDK build tells me:

undefined reference to `sox_open_read'

sox_open_read is defined in sox.h. I know it's finding sox.h because it gives me a warning about that file:

In file included from (...)/sox/sox.h:19

So maybe it wants to find sox_open_read in the actual libsox.so. Well, I've tried about a 100 different ways to tell it where the sox shared lib is e.g.

LOCAL_SHARED_LIBRARY := sox
LOCAL_LDLIBS    := -L$(LOCAL_PATH_FULL)/jni/libs/libsox.so

However, It will work if I specify Sox as a static library:

#LOCAL_SHARED_LIBRARY := sox
LOCAL_STATIC_LIBRARIES := sox
LOCAL_LDLIBS    := -L$(LOCAL_PATH_FULL)/jni/libs/libsox.so

It's my understanding that I don't want to staticly link to the sox lib - I want to dynamically link to it.


回答1:


You should define libsox.so as a prebuilt library. Create a makefile as the following and put your prebuilt libsox.so in the same directory with this makefile. After that, you can use libsox same as you've rebuilt it. Don't forget to include this makefile into your build.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libsox
LOCAL_SRC_FILES := libsox.so

include $(PREBUILT_SHARED_LIBRARY)


来源:https://stackoverflow.com/questions/8582765/android-ndk-linking-problems

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