使用静态库构建共享库的未定义引用错误

时间:2011-04-01 08:49:00

标签: android android-ndk

我很困惑如果我在使用静态库时做错了什么。

进行测试, 我正在尝试使用静态库(mtwist)创建一个共享库(pal)。

但是我得到了对静态库(mtwist)

的功能的未定义引用
Compile thumb  : mtwist <= mtwist.c
Compile thumb  : mtwist <= randistrs.c
StaticLibrary  : libmtwist.a
SharedLibrary  : libpal.so
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `CRandom':
F:/afe/jni/PAL/Sources/PALrandom.cpp:47: undefined reference to `mts_seed'
F:/afe/jni/PAL/Sources/PALrandom.cpp:48: undefined reference to `mts_mark_initialized'
F:/afe/jni/PAL/Sources/PALrandom.cpp:47: undefined reference to `mts_seed'
F:/afe/jni/PAL/Sources/PALrandom.cpp:48: undefined reference to `mts_mark_initialized'
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `PAL::CRandom::
GetRandomInteger16()':
F:/afe/jni/PAL/Sources/PALrandom.cpp:60: undefined reference to `rds_iuniform'
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `PAL::CRandom::GetRandomInteger32()':
F:/afe/jni/PAL/Sources/PALrandom.cpp:67: undefined reference to `rds_iuniform'
F:/afe/jni/PAL/Sources/PALrandom.cpp:69: undefined reference to `rds_iuniform'
collect2: ld returned 1 exit status
make: *** [/cygdrive/f/afe/obj/local/armeabi/libpal.so] Error 1

**看看libmtwist.a已经构建,虽然它为mtwist函数提供了未定义的引用。

这是Android.mk文件mtwist(静态库):

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := mtwist
LOCAL_SRC_FILES := mtwist.c \
            randistrs.c \
include $(BUILD_STATIC_LIBRARY)

这是朋友(共享库)的Android.mk文件:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../Headers \
    $(LOCAL_PATH)/../../BaseMulti/Headers \
    $(LOCAL_PATH)/../../boost \
    $(LOCAL_PATH)/../../mtwist-0.7

LOCAL_CFLAGS += -Wno-deprecated -D_LINUX  -DBOOST_HAS_PTHREADS -fexceptions
LOCAL_MODULE    := pal
LOCAL_SRC_FILES := PALcritsec.cpp \
             PALdebug.cpp \
             PALdebuglog.cpp \
             PALinet.cpp \
             PALlocalhostUdpEvent.cpp \
             PALnetwork.cpp \
             PALpollarray.cpp \
             PALprofiler.cpp \
             PALrandom.cpp \
             PALserializable.cpp \
             PALsocket.cpp \
             PALstringutil.cpp \
             PALsystime.cpp \
             PALthread.cpp \

LOCAL_SHARED_LIBRARIES := boostthread
LOCAL_WHOLE_STATIC_LIBRARIES := mtwist

include $(BUILD_SHARED_LIBRARY)

这是主要的Android.mk文件:

ROOT_DIR := $(call my-dir)
include $(ROOT_DIR)/PAL/Sources/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/boost/libs/thread/src/Android.mk

1 个答案:

答案 0 :(得分:0)

include $(ROOT_DIR)/PAL/Sources/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/boost/libs/thread/src/Android.mk

你有没有为我改变构建顺序,看起来你试图建立朋友,在mtwist之前,我认为提升应该是最重要的。

include $(ROOT_DIR)/boost/libs/thread/src/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/PAL/Sources/Android.mk

为什么要使用一些至少没有记录在r5b中的LOCAL_WHOLE_STATIC_LIBRARIES? (或者至少我找不到;]) 我会用这样的东西:

LOCAL_SHARED_LIBRARIES := boostthread
LOCAL_STATIC_LIBRARIES := mtwist