在android中编译boost时出错

sol*_*lti 5 c++ android boost

我试图根据这个安装boost 1.5到android .

当我编译时,我收到一个错误.这是编译错误的一个片段:

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...
Run Code Online (Sandbox Code Playgroud)

我发现这个错误,我不明白......

./boost/thread/pthread/thread_data.hpp:42: error: 'PAGE_SIZE' was not declared in this scope.它说PAGE_SIZE没有宣布,但我不知道这意味着什么.当我试图查看代码中的特定位置时,我没有找到PAGE_SIZE.

flo*_*son 7

这个问题有1.50提升,ndk-r8b.

感谢这个线程,我设法通过以下更改来修复它:

文件boost/thread/thread.hpp

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

#include <boost/thread/pthread/thread_data.hpp>
Run Code Online (Sandbox Code Playgroud)

请注意,自1.50提升以来我还需要更改它:

文件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
Run Code Online (Sandbox Code Playgroud)


Bri*_*ain 4

像这样的编译错误通常可以通过首先查看预处理的输出来解决。尝试替换-c-E并将 更改foo.ofoo.pp(或其他内容)并检查foo.pp文件是否有错误(搜索set_stack_size)。

这是相关代码:

        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;
Run Code Online (Sandbox Code Playgroud)

getpagesize()扩展为引用的内容PAGE_SIZE。我很确定sysconf这是目前获取页面大小的正确方法(tm),但是 boost 维护者可能有充分的理由使用getpagesize(). 无论如何,您可以使用-DPAGE_SIZE=2048编译器参数或任何目标的页面大小来避免此特定错误。或者,或者修补源代码以sysconf(_SC_PAGESIZE)代替使用。