C++11 交叉编译代码时,boost会导致编译错误

C++11 交叉编译代码时,boost会导致编译错误,c++11,boost,android-ndk,C++11,Boost,Android Ndk,{ubuntu14.0464位,arm-g++编译器4.9google的ndkr10c附带的版本} (我已经为android-14平台制作了一个独立的工具链,--sysroot指出了这一点。同时将标志-march=armv7-a传递给编译器) 在使用arm交叉编译器编译boost时,我在socket_ops.ipp中遇到以下错误: /some-path/thirdparty/boost/boost_1_55_0_Android/boost/interprocess/mapped_region.h

{
ubuntu14.0464位,arm-g++编译器4.9
google的ndkr10c附带的版本}

(我已经为android-14平台制作了一个独立的工具链,
--sysroot
指出了这一点。同时将标志
-march=armv7-a
传递给编译器)

在使用arm交叉编译器编译boost时,我在
socket_ops.ipp
中遇到以下错误:

/some-path/thirdparty/boost/boost_1_55_0_Android/boost/interprocess/mapped_region.hpp:49: error: sys/shm.h: No such file or directory 
 #      include <sys/shm.h>      //System V shared memory...
                                                        ^ 
对于此类型的所有函数(模板):

template <typename SockLenType>
inline int call_getsockname(SockLenType msghdr::*, 
    socket_type s, socket_addr_type* addr, std::size_t* addrlen) 
{ 
  SockLenType tmp_addrlen = (SockLenType)*addrlen; 
  int result = ::getsockname(s, addr, &tmp_addrlen); 
  *addrlen = (std::size_t)tmp_addrlen; 
  return result; 
} 

/some-path/thirdparty/boost/boost_1_55_0_Android/boost/asio/detail/impl/socket_ops.ipp:1639: error: invalid conversion from 'int*' to 'socklen_t* {aka unsigned int*}' [-fpermissive] 
   int result = ::getsockname(s, addr, &tmp_addrlen); 


                                              ^ 
当然,它编译得很好,但我不知道这是否是应该做的

映射的\u区域。hpp

/some-path/thirdparty/boost/boost_1_55_0_Android/boost/interprocess/mapped_region.hpp:49: error: sys/shm.h: No such file or directory 
 #      include <sys/shm.h>      //System V shared memory...
                                                        ^ 
/some path/thirdparty/boost/boost\u 1\u 55\u 0\u Android/boost/interprocess/mapped\u region.hpp:49:错误:sys/shm.h:没有这样的文件或目录
#包括//系统V共享内存。。。
^ 
并指出:

#    if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) 
#      include <sys/shm.h>      //System V shared memory... 
#    endif 
#如果已定义(BOOST_进程间_XSI_共享_内存_对象)
#包括//系统V共享内存。。。
#恩迪夫
在那个档案里

以下是我的user-config.jam文件中的标志:

using gcc : android 
: 
@AndroidNDKSrcDir@/bin/arm-linux-androideabi-g++ 
: 
<archiver>@AndroidNDKSrcDir@/bin/arm-linux-androideabi-ar 
<compileflags>-fexceptions 
<compileflags>-frtti 
<compileflags>-fPIC 
<compileflags>-std=c++11 
<compileflags>-ffunction-sections 
<compileflags>-funwind-tables 
<compileflags>-D__ARM_ARCH_5__ 
<compileflags>-D__ARM_ARCH_5T__ 
<compileflags>-D__ARM_ARCH_5E__ 
<compileflags>-D__ARM_ARCH_5TE__ 
<compileflags>-Wno-psabi 
<compileflags>-march=armv5te 
<compileflags>-mtune=xscale 
<compileflags>-msoft-float 
<compileflags>-mthumb 
<compileflags>-Os 
<compileflags>-fomit-frame-pointer 
<compileflags>-fno-strict-aliasing 
<compileflags>-finline-limit=64 
<compileflags>-I@AndroidNDKSrcDir@/include/c++/4.9 
<compileflags>-Wa,--noexecstack 
<compileflags>-DANDROID 
<compileflags>-D__ANDROID__ 
<compileflags>-DNDEBUG 
<compileflags>-O2 
<compileflags>-g 
<compileflags>-I@AndroidNDKSrcDir@/sysroot/usr/include 
<architecture>arm 
<compileflags>-fvisibility=hidden 
<compileflags>-fvisibility-inlines-hidden 
<compileflags>-fdata-sections 
<cxxflags>-D__arm__ 
<cxxflags>-D_REENTRANT 
<cxxflags>-D_GLIBCXX__PTHREADS 
; 
使用gcc:android
: 
@AndroidNDKSrcDir@/bin/arm-linux-Androidabi-g++
: 
@AndroidNDKSrcDir@/bin/arm-linux-androideabi-ar
-例外情况
-弗蒂
-fPIC
-std=c++11
-F功能部分
-funwind表
-D_uu臂_u拱_u5_uu
-D_uu臂_u拱_u5t_uu
-D_uu臂_u拱_u5e_uu
-D_uu臂_u拱_u5te_u
-普萨比酒店
-三月=armv5te
-mtune=xscale
-msoft浮动
-姆图姆
-操作系统
-fomit帧指针
-fno严格混叠
-鳍线极限=64
-I@AndroidNDKSrcDir@/包括/c++/4.9
-Wa,--noexecstack
-蒲公英
-安卓机器人
-DNDEBUG
-氧气
-g
-I@AndroidNDKSrcDir@/sysroot/usr/include
手臂
-可视性=隐藏
-隐藏的可视性内联线
-fdata节
-手臂
-D_可重入
-D_GLIBCXX_uupthreads
; 
对于上面的两个错误——,前进的道路是什么?boost(asio等)Android是否具备c++11功能?

无论出于何种原因,您都有不兼容的
。您建议的“修复”将编译,但在运行时崩溃。以下是最简单的解决方案:

int tmp_addrlen = (int)*addrlen; 
int result = ::getsockname(s, addr, &tmp_addrlen); 

在Android上,这种类型转换是不安全的,但看在上帝的份上,没有人会使用超过2^32的addrlen。

对于
,无论是谁调用
call\u getsockname
都会在第一个参数中传递
int
类型的数据成员指针,而它应该是
unsigned
。为什么这甚至是一个模板参数?它总是需要
无符号
(或者更准确地说,
socklen\t
)。。。或者你的意思是
socklen\u t tmp\u addrlen=(socklen\u t)*addrlen相反,以便传递任何整数类型?您的代码如何准确调用函数?@ildjarn
为什么这甚至是一个模板参数?
函数属于boost本身,我不知道为什么它会被模板化。@AlexCohn:这是一个boost impl文件。如果您看到函数就在它的正下方,即,
getsockname
,它将传递它
&msghdr::msg_namelen
,即
int*
。因此,这是一种激励。编辑:并且(
getsockname
)不是一个函数模板,因此仅仅包含头文件就会导致编译错误。因此,您要么没有包含正确的
,要么在某个地方定义了覆盖它的
。更新:对于android-21,
socklen\u t
可以在
中定义为未签名。