如果在使用静态库时做错了什么,我会感到困惑。
供测试用,
我正在尝试使用静态库(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)
这是pal(共享库)的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
最佳答案
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之前尝试构建pal一样,我认为应该将其放在首位。
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