Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling STXXL under Android NDK r8b

I'm trying to compile STXXL under Android NDK r8b (I have the same problem under the newer r8c btw).

I'm compiling using gnustl_static.

I need C++11 support so initially I tried setting

LOCAL_CPPFLAGS := -std=c++11

but this threw up an error about uint64_t.

So I changed the flag to

LOCAL_CPPFLAGS :=-std=gnu++11

This helps a fair bit but when it starts compiling I get an error relating to the gnu stl.

Users/Gozzeh/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/stxxl/STXXL/algo/copy_and_sort_file.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I/Users/Gozzeh/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include -I/Users/Gozzeh/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include -Ijni -DANDROID  -Wa,--noexecstack -fexceptions -frtti -Dnullptr=0 -D_ANDROID -std=gnu++11 -Ijni/STXXL/include -fexceptions  -O2 -DNDEBUG -g   -I/Users/Gozzeh/android-ndk-r8b/platforms/android-8/arch-arm/usr/include -c  jni/STXXL/algo/copy_and_sort_file.cpp -o ./obj/local/armeabi/objs/stxxl/STXXL/algo/copy_and_sort_file.o 
In file included from /Users/Gozzeh/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/set:60:0,
                 from jni/STXXL/include/stxxl/bits/io/simdisk_file.h:33,
                 from jni/STXXL/include/stxxl/bits/io/io.h:20,
                 from jni/STXXL/include/stxxl/io:13,
                 from jni/STXXL/algo/copy_and_sort_file.cpp:18:
/Users/Gozzeh/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h: In member function 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Base_ptr, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Base_ptr, const _Val&)':
/Users/Gozzeh/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:1011:39: error: '_Arg' was not declared in this scope

I also get a whole load more errors relating to this _Arg parameter.

So looking at the first one the function looks like the following:

template<typename _Key, typename _Val, typename _KeyOfValue,
           typename _Compare, typename _Alloc>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
    template<typename _Arg>
#endif
    typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator
    _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
#ifdef __GXX_EXPERIMENTAL_CXX0X__
    _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, _Arg&& __v)
#else
    _M_insert_(_Const_Base_ptr __x, _Const_Base_ptr __p, const _Val& __v)
#endif
    {
      bool __insert_left = (__x != 0 || __p == _M_end()
                || _M_impl._M_key_compare(_KeyOfValue()(__v), 
                              _S_key(__p)));

      // This line is the error location.
      _Link_type __z = _M_create_node(_GLIBCXX_FORWARD(_Arg, __v)); 

      _Rb_tree_insert_and_rebalance(__insert_left, __z,
                    const_cast<_Base_ptr>(__p),  
                    this->_M_impl._M_header);
      ++_M_impl._M_node_count;
      return iterator(__z);
    }

I can't really understand where the problem is arising. Is gnu++11 not defining __GXX_EXPERIMENTAL_CXX0X__? Or is the problem that it's not being used somewhere properly? I'm very confused as to what is causing the problem? I have STXXL compiling with gnu++11 under clang on the iphone but I guess that iphone is probably using a different STL implementation. Has anyone got any ideas on how I can fix this problem?

If you need any further info just ask!

Edit: So further to one of the comments here is my application.mk

APP_PLATFORM := android-8 
APP_STL      := gnustl_static
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti 
APP_OPTIM    := release APP_ABI      := all

and this is my android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
rwildcard       = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

LOCAL_MODULE    := stxxl
LOCAL_CPP_FEATURES += exceptions
FILE_LIST       := $(call rwildcard, $(LOCAL_PATH)/STXXL/,*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_CPPFLAGS  := -Dnullptr=0 -D_ANDROID -D__STDC_INT64__ -std=gnu++11 -I$(LOCAL_PATH)/STXXL/include
include $(BUILD_SHARED_LIBRARY)

Edit: Interestingly I just tried placing a #error temp inside the #ifdef __GXX_EXPERIMENTAL_CXX0X__ block in the stl_tree.h function i posted. The compiler does NOT throw an error on that part ... so the define is never getting set which is, presumably, the cause of my issues. I've also specifically added a -D__GXX_EXPERIMENTAL_CXX0X__ but that makes no difference (its as if it gets undef'd).

like image 902
Goz Avatar asked Nov 15 '12 08:11

Goz


1 Answers

I think your approach to build is too optimistic. I don't know anything about STXXL but any non trivial project has a lot of details in their own make files so by throwing your own Android.mk and trying to include all possible source code files to build shouldn't work.

If you want to utilize ndk-build, you should carefully study the project and understand its details and incorporate those to your newly Android.mk file. For example if you check external directory under Android repository (in github they are listed as several sub projects) you can see many open source projects and how they are introduced to Android build system.

After long and boring message, what I would suggest is to use NDK as a standalone tool chain. You can read about this $NDK/docs/STANDALONE-TOOLCHAIN.html. In short I was able to compile STLXX as a static library via the command below (my ndk was installed at ~/bin)

NDK=~/bin/android-ndk-r8c PTHREAD_FLAG= COMPILER="$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ --sysroot=$NDK/platforms/android-14/arch-arm -I$NDK/sources/cxx-stl/gnu-libstdc++/4.6/include -I$NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include -L$NDK/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/ -lgnustl_shared" make library_g++

At first build fails with a problem in file ./io/ufs_file_base.cpp. There are some obsolete uses of S_IREAD and S_IWRITE which is not supported by Android / Bionic. See bug report and reference.

You should update the line 88 as below

const int perms = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;

then

<same build command again>

now you should get libstxxl.a under lib. I don't know if this is really works or not but since this was a build question, I hope it answers or gives you some directions.

One last note is about ARM EABIs. Above command uses armeabi as you can see in specified directories, you might want to use armeabi-v7a if applicable to your target since that's newer. From your error messages I can see that particular build was targeting xscale, if that's not intentional it might be a good idea to get yourself familiarized with ARM architecture / product families.

like image 106
auselen Avatar answered Sep 28 '22 09:09

auselen