Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error while compiling boost in android

Tags:

c++

android

boost

I am trying to install boost 1.5 into android according to this.

When I compile, I get an error. Here is a fragment of the compilation error:

gcc.compile.c++ bin.v2/libs/thread/build/gcc-android4.4.3/release/link-static/runtime-link-    static/threading-multi/pthread/thread.o
<command-line>: warning: "BOOST_FILESYSTEM_VERSION" redefined
<command-line>: warning: this is the location of the previous definition
In file included from ./boost/thread/thread.hpp:17,
             from libs/thread/src/pthread/thread.cpp:11:
./boost/thread/pthread/thread_data.hpp: In member function 'void    boost::thread_attributes::set_stack_size(size_t)':
./boost/thread/pthread/thread_data.hpp:42: error: 'PAGE_SIZE' was not declared in this scope

"../../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic --sysroot=../../platforms/android-9/arch-arm -mthumb -Os -fno-strict-aliasing -O2 -DNDEBUG -g -lstdc++ -I../../sources/cxx-stl/gnu-libstdc++/include -I../../sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -D__GLIBC__ -DBOOST_NO_INTRINSIC_WCHAR_T -DBOOST_FILESYSTEM_VERSION=2 -pthread -Wextra -Wno-long-long -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_STATIC_LINK=1 -DBOOST_FILESYSTEM_VERSION=3 -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_POSIX -DNDEBUG  -I"." -c -o "bin.v2/libs/thread/build/gcc-android4.4.3/release/link-static/runtime-link-static/threading-multi/pthread/thread.o" "libs/thread/src/pthread/thread.cpp"

...failed gcc.compile.c++ bin.v2/libs/thread/build/gcc-android4.4.3/release/link-static/runtime-link-static/threading-multi/pthread/thread.o...

I found this error which I didn't understand ...

./boost/thread/pthread/thread_data.hpp:42: error: 'PAGE_SIZE' was not declared in this scope. It says PAGE_SIZE was not declared, but I have no idea what that means. And when I tried to look at that particular location in the code I did not find PAGE_SIZE.

like image 694
solti Avatar asked Jul 12 '12 02:07

solti


2 Answers

Had this issue with 1.50 boost, ndk-r8b.

Thanks to this thread I managed to get it fixed with following changes :

file boost/thread/thread.hpp

// Fix for missing macro
#define PAGE_SIZE sysconf(_SC_PAGESIZE)

#include <boost/thread/pthread/thread_data.hpp>

Note that I also needed to change this since the 1.50 boost:

file boost/libs/filesystem/src/operations.cpp

# ifdef BOOST_POSIX_API

    const fs::path dot_path(".");
    const fs::path dot_dot_path("..");
#   include <sys/types.h>
#   include <sys/stat.h>
#   if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(ANDROID)
#     include <sys/statvfs.h>
#     define BOOST_STATVFS statvfs
#     define BOOST_STATVFS_F_FRSIZE vfs.f_frsize
#   elif defined (ANDROID)
#     include <sys/vfs.h>
#     define BOOST_STATVFS statfs
#     define BOOST_STATVFS_F_FRSIZE static_cast<boost::uintmax_t>(vfs.f_bsize)
#   else
#     ifdef __OpenBSD__
#     include <sys/param.h>
#     endif
#     include <sys/mount.h>
#     define BOOST_STATVFS statfs
#     define BOOST_STATVFS_F_FRSIZE static_cast<boost::uintmax_t>(vfs.f_bsize)
#   endif
like image 171
florentbuisson Avatar answered Oct 03 '22 22:10

florentbuisson


Compilation errors like this are typically resolved by looking first at the preprocessed output. Try replacing -c with -E and changing the foo.o to foo.pp (or something else) and review the foo.pp file for errors (search for set_stack_size).

This is the relevant code:

        void set_stack_size(std::size_t size) BOOST_NOEXCEPT {
          if (size==0) return;
          std::size_t page_size = getpagesize();
#ifdef PTHREAD_STACK_MIN
          if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
#endif
          size = ((size+page_size-1)/page_size)*page_size;

getpagesize() expands to something which references PAGE_SIZE. I'm pretty sure sysconf is the Right Way (tm) to get the page size these days, but the boost maintainers might've had a good reason for using getpagesize(). Regardless, you can dodge this specific error with a -DPAGE_SIZE=2048 compiler argument, or whatever your target's page size is. Either that, or patch the source to use sysconf(_SC_PAGESIZE) instead.

like image 26
Brian Cain Avatar answered Oct 03 '22 22:10

Brian Cain