简体   繁体   中英

Strange NDK compilation with an arbitrary Boost library

In my JNI code, I am only using boost/share_ptr.h But I didn't know which library I should include and for place-holder to work with it later, I just added boost_date library in Android.mk like this.

LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -ldl
LOCAL_CFLAGS := -I$(LOCAL_PATH)/boost
LOCAL_MODULE    := mathparser
LOCAL_SRC_FILES := main.cpp pmain.cpp
LOCAL_STATIC_LIBRARIES := boost_date 
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost)  

Surprisingly, it succeeded to compile and generate shared library. May I ask why it worked? Does this mean I can include any static library of Boost for shared_ptr?

That's because the shared_ptr.hpp is a header library. It is basically a template so when you write:

boost::shared_ptr<YourClass> yourPtr;

the compiler generates the shared_ptr code adapted to the class "YourClass" for the first time. As the final code depends on which class you use there is no binary library.

As most of the boost libraries are templates and therefore headers libraries you don't need to do anything special in android to use them apart of include them. In their documentation page they indicate which libraries are header only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM