Tae-Sung Shin
Tae-Sung Shin

Reputation: 20620

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?

Upvotes: 1

Views: 347

Answers (1)

javier-sanz
javier-sanz

Reputation: 2524

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.

Upvotes: 1

Related Questions