Android NDK linking problems

2019-09-02 22:07发布

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条回答
我命由我不由天
2楼-- · 2019-09-02 23:05

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)
查看更多
登录 后发表回答