Long_GM
Long_GM

Reputation: 191

Android NDK call API of a static library inside a shared library

I have a shared library, named libwrapper.so , this library, in turn, uses another static library named libcore.a. Here is the Android.mk

## core module
include $(CLEAR_VARS)
LOCAL_MODULE := core
MY_SRC_DIR := src
MY_SRC_FILES := core.cpp core2.cpp
LOCAL_SRC_FILES := $(addprefix $(MY_SRC_DIR)/, $(MY_SRC_FILES))
include $(BUILD_STATIC_LIBRARY)


## wrapper module
include $(CLEAR_VARS)
LOCAL_MODULE := wrapper
MY_SRC_DIR := src
MY_SRC_FILES := wrapper.cpp
LOCAL_SRC_FILES := $(addprefix $(MY_SRC_DIR)/, $(MY_SRC_FILES))
LOCAL_STATIC_LIBRARIES := core
include $(BUILD_SHARED_LIBRARY)

The strange thing is, when I use command "nm -D libwrapper.so" only symbols of those functions in core.cpp are seen. Why core2.cpp doesn't export any function??

Upvotes: 1

Views: 130

Answers (1)

Long_GM
Long_GM

Reputation: 191

Problem sovled, I found that the reason is wrapper module only calls code from core.cpp not core2.cpp, hence optimizer clean dead code. To prevent it, use LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES

replace

LOCAL_STATIC_LIBRARIES := core

by this

LOCAL_WHOLE_STATIC_LIBRARIES := core

Upvotes: 1

Related Questions