开发者

Undefined reference error using static library to build shared library

开发者 https://www.devze.com 2023-02-21 00:55 出处:网络
I am confused If I am doing something wrong while using the static library. For testing, I\'m trying to make a shared library(pal) using a static library(mtwist).

I am confused If I am doing something wrong while using the static library.

For testing, I'm trying to make a shared library(pal) using a static library(mtwist).

But I am getting undefined reference to the functions of the static library(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:/开发者_如何学Pythonafe/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

**Look libmtwist.a has been built though its giving undefined reference for the mtwist functions.

This is the Android.mk file mtwist(Static Library):

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

This is the Android.mk file of pal (Shared Library):

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)

and this is the main Android.mk file:

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

Did you trie to change build order for me it looks like you try to build pal, before mtwist, and i think boost should be at top of it.

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

And why use some LOCAL_WHOLE_STATIC_LIBRARIES that's not documented at least not in r5b? ( or at least i can not find ;] ) I would use something like this:

LOCAL_SHARED_LIBRARIES := boostthread
LOCAL_STATIC_LIBRARIES := mtwist
0

精彩评论

暂无评论...
验证码 换一张
取 消