1

我正在尝试编译一个 NDK 项目。因为我必须使用外部.so-文件。它被编译为名称 libpcan.so.0.6 因为 makefile 正在编译这个库是:

LDNAME = libpcan.so
SONAME = $(LDNAME).0
TARGET = $(SONAME).6

我的 receivetest.c-File 需要这个 libpcan.so.0.6 包含的函数。android-toolchain 不接受文件结尾的“.so.0.6”,所以我将文件重命名为 libpcan.so 。我的 Android.mk 将此 .so 作为 PREBUILD_SHARED_LIBRARY 来编译我的 receivetest.so 。工具链正常工作。

当我启动我的 Android 应用程序时,我收到错误消息:

 java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]:    36 could not load needed library 'libpcan.so.0' for 'libreceivetest.so' (load_library[1093]: Library 'libpcan.so.0' not found)*

所以我的问题是:我可以在创建 .so 文件后重命名它而不引起问题吗?为什么应用程序要加载 libpcan.so.0,在将 .so.0.6 重命名为 .so 并且这个 .so 在 ndk-toolchain 中运行良好?

4

1 回答 1

0

Android.mk 编译我的 receivetest.so

LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=libpcan
LOCAL_SRC_FILES :=libpcan.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=common
LOCAL_SRC_FILES := common.c
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE :=receivetest
LOCAL_SRC_FILES := receivetest.c
LOCAL_STATIC_LIBRARIES:=common 
LOCAL_SHARED_LIBRARIES:=libpcan
include $(BUILD_SHARED_LIBRARY)

编译 pcan.so.0.6 的外部 Makefile 相当长:

CC := arm-linux-androideabi-gcc
SRC     = src
INC     = -I. -I../driver
FILES   = $(SRC)/libpcan.c
DBG     = -g
RT      = NO_RT

ifeq ($(RT), XENOMAI)
# Define flags for XENOMAI installation only
#
USB = NO_USB_SUPPORT
PCC = NO_PCCARD_SUPPORT

INC     = -I. -I../driver -I/usr/xenomai/include
SKIN = xeno
RT_DIR          ?= /usr/xenomai
RT_CONFIG       ?= $(RT_DIR)/bin/xeno-config
RT_LIB_DIR      ?= $(shell $(RT_CONFIG) --library-dir) -Wl,-rpath $(shell $(RT_CONFIG) --library-dir)
RT_CFLAGS       ?= $(shell $(RT_CONFIG) --$(SKIN)-cflags)
endif

ifeq ($(RT), RTAI)

# Define flags for RTAI installation only
#
USB = NO_USB_SUPPORT
PCC = NO_PCCARD_SUPPORT

INC     = -I. -I../driver -I/usr/realtime/include

SKIN = lxrt
RT_DIR          ?= /usr/realtime
RT_CONFIG       ?= $(RT_DIR)/bin/rtai-config
RT_LIB_DIR      ?= $(shell $(RT_CONFIG) --library-dir) -Wl,-rpath $(shell $(RT_CONFIG) --library-dir)
RT_CFLAGS       ?= $(shell $(RT_CONFIG) --$(SKIN)-cflags)
endif

ifeq ($(HOSTTYPE),x86_64)
  LIBPATH = /usr/lib64
else
  LIBPATH = /usr/lib
 endif
INCPATH = /usr/include

LDNAME  = libpcan.so
SONAME  = $(LDNAME).0
TARGET  = $(SONAME).6

ifneq ($(RT), NO_RT)
  CFLAGS = -fPIC -shared -O2 -Wall -Wl,-soname,$(SONAME) -lc $(INC) -D$(RT) $(RT_CFLAGS) -L$(RT_LIB_DIR) -lrtdm
else
  CFLAGS = -fPIC -shared -O2 -Wall -Wl,-soname,$(SONAME) -lc $(INC) -D$(RT)
endif

all:    $(TARGET)

 $(TARGET) : $(FILES)
# ln -sf ../driver/pcan.h pcan.h
$(CC) $(FILES) $(CFLAGS) -o $(TARGET)
ln -sf $(TARGET) $(LDNAME)

clean:
rm -f $(SRC)/*~ $(SRC)/*.o *~ *.so.*


install:
mkdir -p $(DESTDIR)$(LIBPATH)
cp $(TARGET) $(DESTDIR)$(LIBPATH)/$(TARGET)
ln -sf $(DESTDIR)$(LIBPATH)/$(TARGET) $(DESTDIR)$(LIBPATH)/$(SONAME)
ln -sf $(DESTDIR)$(LIBPATH)/$(SONAME) $(DESTDIR)$(LIBPATH)/$(LDNAME)
mkdir -p $(DESTDIR)$(INCPATH)
cp libpcan.h $(DESTDIR)$(INCPATH)/libpcan.h
chmod 644 $(DESTDIR)$(INCPATH)/libpcan.h
ifeq ($(DESTDIR),)
/sbin/ldconfig
endif

uninstall:
@-rm -f $(DESTDIR)$(LIBPATH)/$(TARGET)
@-rm -f $(DESTDIR)$(LIBPATH)/$(SONAME) $(DESTDIR)$(LIBPATH)/$(LDNAME)
@-rm -f $(DESTDIR)$(INCPATH)/libpcan.h
ifeq ($(DESTDIR),)
/sbin/ldconfig
endif

由于 RT = NO_RT 只考虑 ifeq NO_RT 重要的部分。

于 2013-07-04T08:46:41.647 回答