0

I've been trying to link boost into my android application following these instructions:

Include Boost C++ library in android

which seems to be pretty concise and sensible. Unfortunately, after days of trying I can't see what I'm doing wrong, as the end result is that ndk-build returns "No such file or Directory" regarding the boost headers I try to include.

After building the boost libraries I needed, I copied them in proj.android/jni/boost/include and proj.android/jni/boost/lib. I then created a directory in jni called boost-build, where I created an Android.mk to handle define the module to link to the libboost_serialization static library (which is the only boost library I'm interested in).

LOCAL_PATH:= $(call my-dir)

# serialization
include $(CLEAR_VARS)

# I'm not sure this is necessary / helpful, but I've tried without it, as well
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/boost-1_49 \
# EDIT: replaced previous line from this, at Igor's correction: $(LOCAL_PATH)/../include/boost-1_49/boost \
                    $(LOCAL_PATH)/../include/boost-1_49/boost/archive \
                    $(LOCAL_PATH)/../include/boost-1_49/boost/serialization

LOCAL_MODULE:= boost_serialization
LOCAL_SRC_FILES:= ../lib/libboost_serialization-gcc-mt-1_49.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/boost-build-includes
include $(PREBUILT_STATIC_LIBRARY)

The android project makefile, proj.android/jni/Android.m:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LDFLAGS= -L$(NDK_ROOT)/sources/crystax/libs/armeabi-v7a/4.6.3 -Lcrystax 

LOCAL_CPPFLAGS += -fexceptions 

LOCAL_CPPFLAGS += -frtti

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \
        ../../Classes/TitleScene.cpp \
        ../../Classes/GameSettings.cpp \
        ../../Classes/Cutscene.cpp \
        ../../Classes/HighScoreTable.cpp \
        ../../Classes/MaskNode.cpp \
        ../../Classes/MenuResponder.cpp \
        ../../Classes/HudElementBg.cpp \
        ../../Classes/OHRCharSelectMenu.cpp \
        ../../Classes/OHRDifficultySelectMenu.cpp \
        ../../Classes/Types.cpp \
        ../../Classes/OHRMainMenu.cpp

# I've tried with / without this variable, as well, with the same result
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../include/boost-1_49 \
# EDIT: replaced previous line from this, at Igor's correction: $(LOCAL_PATH)/../include/boost-1_49/boost \
        $(LOCAL_PATH)/../boost/include/boost-1_49/boost/archive \
        $(LOCAL_PATH)/../boost/include/boost-1_49/boost/serialization

LOCAL_WHOLE_STATIC_LIBRARIES := boost_serialization cocos2dx_static cocosdenshion_static cocos_extension_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) \
$(call import-module,boost-build) \
$(call import-module,cocos2dx)

Now, when I run ndk-build to compile my source, I get the following error:

Compile++ thumb  : game_shared <= main.cpp
Compile++ thumb  : game_shared <= AppDelegate.cpp
In file included from jni/../../Classes/MapUtils.h:2:0,
                 from jni/../../Classes/Types.h:3,
                 from jni/../../Classes/menuresponder.h:2,
                 from jni/../../Classes/OHRMainMenu.h:2,
                 from jni/../../Classes/TitleScene.h:10,
                 from jni/../../Classes/AppDelegate.cpp:6:

jni/../../Classes/BoostUtils.h:2:36: fatal error: boost/archive/tmpdir.hpp: No such file or directory

(BoostUtils.h being a header that simply includes a bunch of serialization-related headers)

#include <boost/archive/tmpdir.hpp>

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>

#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/assume_abstract.hpp>

Now, exactly once tonight, running this generated a bunch of .so's and .a's, include libbost_serialization.so, in proj.android/obj/local. I have not been able to get that to be generated since, despite deleting the /obj directory. Also odd is that, despite what's suggested by the link at the top of this post, a /libs directory is not being created when ndk-build is run. However, I'm not 100% sure that .so even needs to be generated.

So, for the life of me I can't identify the problem here. Any solutions or direction would be much, much appreciated.

Community
  • 1
  • 1
Wes Paugh
  • 161
  • 1
  • 10
  • You include path seems to be incorrect. It should point to the root of boost installation: $(LOCAL_PATH)/../include/boost-1_49/ – Igor R. Jan 16 '13 at 10:36
  • Good catch! That was not the only edit needed, but it got me to look for the right problem. In addition to your correction, the Android.mk within jni/, I also was going up to the parent directory when including boost headers. Thank you! – Wes Paugh Jan 16 '13 at 12:44

1 Answers1

1

Lesson learned: LOCAL_C_INCLUDES actually is a necessary variable, and make sure it's pointing to the right place. In my case, it was just an errant '../' and including the contents of 'boost/', rather than the directory containing boost.

(Also, sleep more, rather than spend hours glancing over these issues.)

Wes Paugh
  • 161
  • 1
  • 10