Android: segfault while writing to archive during Serialization

Greetings! New to discussion, apologies in advance for any inadvertent misuse of terminology / standards. (also, I tried e-mailing this post directly last night, but it doesn't appear to have shown up, yet. double-apologies if double-post). I'm trying to port my project, which involves some serialization code, to Android. I followed instructions to build boost 1.49 found here: https://github.com/MysticTreeGames/Boost-for-Android and can successfully compile my application using crystax NDK r7 (gcc 4.5.3) , and link it to the Serialization library. Unfortunately! When my application calls the serialization code to send my object to the archive, it crashes. I've reduced my actual code to try and isolate the crash in a way I can post here. std::ofstream outStream(MAP_SAVE_FILE, std::ios_base::binary); boost::archive::text_oarchive outputArchive(outStream, 1); Classroom *c = new Classroom(); CCLog("Outputting archive"); // outputArchive << mapInstance; outputArchive << c; The crash occurs at outputArchive << c; "Fatal signal 11 (SIGEGV) at 0xdeadbaad (code=1), thread 1870 (Thread-97)" which is a segfault, in Androidvania. Ideally I want to be outputting that mapInstance variable that's commented out to archive, but for sanity's sake I made a silly little Classroom class, which I'll include for sanity's sake: class Classroom { friend class boost::serialization::access; template <class Archive> void serialize( Archive &ar, const unsigned int version ) { ar & studentCount; } int studentCount; public: Classroom() { studentCount = 1; } ~Classroom(){} }; I've run across several red flags about wchar support in Android or on gcc versions, so I'm inclined to think that's related. Then again, it appears as though my boost configuration files were aware of the compiler version when it built (that Mystic Tree link at the top really does seem to be on top of things, if anyone's interested), which is how the program was able to compile and run, at all. I'm almost 100% certain this is related to the Android NDK, either the gcc version or the gnu-stl, because I can compile and run this code on Windows through Visual studio with no problem, but it crashes on Android. I've made sure that my app has write permissions to the internal storage being used. I can even write out text files using basic std::ostreams without a crash. I am not at all familiar with dealing with these sorts of compiler- or platform-specific issues; I have a bachelor's in SE which taught me design patterns, architecture, and project management, but nothing like this. I'd greatly appreciate some direction in learning how to work through these kinds of problems, (although I'd even more greatly appreciate an actual solution to the problem I'm seeing). Thanks in advance for any assistance. -- View this message in context: http://boost.2283326.n4.nabble.com/Android-segfault-while-writing-to-archive... Sent from the Boost - Users mailing list archive at Nabble.com.

New to discussion, apologies in advance for any inadvertent misuse of terminology / standards. (also, I tried e-mailing this post directly last night, but it doesn't appear to have shown up, yet. double-apologies if double-post).
I'm trying to port my project, which involves some serialization code, to Android. I followed instructions to build boost 1.49 found here:
https://github.com/MysticTreeGames/Boost-for-Android
and can successfully compile my application using crystax NDK r7 (gcc 4.5.3) , and link it to the Serialization library.
Perhaps, it's worth building the most recent boost version with the latest NDK/toolchain? FWIW, boost1.53 gets built with the standard NDK r8d flawlessly (at least, the libs I need). I'm using the following b2 line: b2 release --with-serialization --with-thread --with-date_time --with-system --with-filesystem --layout=system threading=multi link=static runtime-link=static toolset=gcc-android target-os=linux threadapi=pthread stage and my user-config.jam is as follows (note that it uses gcc 4.7 toolchain, which is not the default in r8d): import os ; if [ os.name ] = CYGWIN || [ os.name ] = NT { androidPlatform = windows ; } else if [ os.name ] = LINUX { androidPlatform = linux-x86 ; } else if [ os.name ] = MACOSX { androidPlatform = darwin-x86 ; } androidNDKRoot = C:/android-ndk-r8d ; using gcc : android : $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ : <compileflags>--sysroot=$(androidNDKRoot)/platforms/android-8/arch-arm <compileflags>-mthumb <compileflags>-Os <compileflags>-fno-strict-aliasing <compileflags>-O2 <compileflags>-DNDEBUG <compileflags>-g <compileflags>-lstdc++ <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/include <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include <compileflags>-D__GLIBC__ <compileflags>-D_GLIBCXX__PTHREADS <compileflags>-D__arm__ <compileflags>-D_REENTRANT <archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar <ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib ;

I've spent the last few weeks trying to work from this, but still keep hitting roadblocks. Usually, these are to the tune of ./boost/..../XXX.hpp: fatal error: bits/c++config.h: No such file or directory Depending on the day, I might have been getting that error about c++config.h, or locale, or cstddef, or stddef.h. The pattern has been "poke at it until I get frustrated, then try from scratch again and get a different file 'missing' ". My user-config.jam is unchanged from what you provided for me: import os ; if [ os.name ] = CYGWIN || [ os.name ] = NT { androidPlatform = windows ; } androidNDKRoot = /cygdrive/c/Android/android-ndk-r8d ; cxxSource = /cygdrive/c/Android/boost-custom/boost_1_53_0/ndk-cxx ; using gcc : android : $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ : <compileflags>--sysroot=$(androidNDKRoot)/platforms/android-8/arch-arm <compileflags>-mthumb <compileflags>-Os <compileflags>-fno-strict-aliasing <compileflags>-O2 <compileflags>-DNDEBUG <compileflags>-g <compileflags>-lstdc++ <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/include <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include <compileflags>-D__GLIBC__ <compileflags>-D_GLIBCXX__PTHREADS <compileflags>-D__arm__ <compileflags>-D_REENTRANT <archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar <ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib ; And I can see, in this case, c++config.h exists at bits/c++config.h under the second directory in the provided search path. The 'No such file' error has always been about a file that I've understood to be in the search path. This is very probably just a gcc quirk I'm not understanding, and not related to boost (sorry). For reference, I'm trying to compile boost with the line: b2 release --with-serialization --with-system --with-filesystem --layout=system link=static runtime-link=static toolset=gcc-android target-os=linux stage Which I think is the subset of your example I need. It seems unlikely that excluding libraries like date_time would be necessary or that threading would be related, but I thought it worth mentioning. One other thing that might be worth mentioning: sometimes the error has been: 'CreateProcess: no such file or directory', which as far as I can tell, isn't referring to a file. I've spent a few days googling that error, as well, and the closest I got to anything resembling an answers was 'cygwin memory problem'. I've adjusted my environment variables to give cygwin more overhead. Haven't seen the problem since restarting my computer again this morning, but I have still seen it since giving cygwin run of more memory. If that could be related to boost, it might be very worth knowing. -- View this message in context: http://boost.2283326.n4.nabble.com/Android-segfault-while-writing-to-archive... Sent from the Boost - Users mailing list archive at Nabble.com.

My user-config.jam is unchanged from what you provided for me:
import os ;
if [ os.name ] = CYGWIN || [ os.name ] = NT { androidPlatform = windows ; }
androidNDKRoot = /cygdrive/c/Android/android-ndk-r8d ; cxxSource = /cygdrive/c/Android/boost-custom/boost_1_53_0/ndk-cxx ;
Why cygdrive? The recent NDK does not use cygwin, the paths should be windows path - just like in the example I provided!

I see. Yes, I hadn't thought Cygwin would be causing problems. Thanks to this, and some help from you on Stack Overflow, I've at least managed to compile libboost_serialization.a against ndk r8d. Unfortunately, when I go to build my app, I am now getting: ./boost/archive/impl/xml_iarchive_impl.ipp:71:error: undefined reference to 'mbtowc' (four instances of that in that file) ./boost/archive/iterators/mb_from_wchar.hpp:91 error: undefined reference to 'wctomb' (two instances of that in that file) I see three possibilities: 1. NDK r8 doesn't support these methods. I've heard / seen this many places, and the solution has been 'use CrystaX r7'. Following that train of thought back in January lead me to the problems at the start of this thread. So, maybe I just need to write these functions myself. I'm not very comfortable writing low-level C code to do so, but I could probably figure it out. I've come across some documentation of what they're supposed to do. 2. NDK r8 does support these functions, but there are some flags I need to set before the NDK will know to include them. I sort of see some macros in those stl files that might be doing something like this, but I could use some help in knowing how to employ them in my code or makefiles. 3. Something else entirely that I haven't considered. It seems odd that I was able to build libboost_serialization.a at all against the NDK when it requires these functions... but maybe it only compiled against archive headers, and didn't require the mbtowc and its complement be defined anywhere? In any case, I am once again stumped by this issue. -- View this message in context: http://boost.2283326.n4.nabble.com/Android-segfault-while-writing-to-archive... Sent from the Boost - Users mailing list archive at Nabble.com.

./boost/archive/impl/xml_iarchive_impl.ipp:71:error: undefined reference to 'mbtowc' (four instances of that in that file) ./boost/archive/iterators/mb_from_wchar.hpp:91 error: undefined reference to 'wctomb' (two instances of that in that file)
Alas, it seems that these functions are still missing in the NDK, that's a bad surprise. I believe you can take their implementation from Crystax NDK or from "The Standard C Library" book, as proposed in one of the answers on SO.
participants (2)
-
Igor R
-
wespaugh