如何为Android编译Boost?Dockcross交叉编译报错求助
问题
我正尝试在Dockcross容器中为Android交叉编译Boost,容器已配置好AS、AR、CC、CXX、LD等指向工具链的环境变量,执行命令如下:
$ ./bootstrap.sh $ ./b2 architecture=arm address-model=32 binary-format=elf abi=aapcs target-os=android
希望通过向./b2传递所有参数,不使用user-config.jam文件,但出现编译错误:
"g++" -x assembler-with-cpp -O3 -finline-functions -Wno-inline -Wall -fvisibility=hidden -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_SOURCE -DBOOST_DISABLE_ASSERTS -DNDEBUG -I"." -c -o "bin.v2/libs/context/build/gcc-10/release/abi-aapcs/address-model-32/architecture-arm/link-static/target-os-android/threading-multi/visibility-hidden/asm/jump_arm_aapcs_elf_gas.o" "libs/context/src/asm/jump_arm_aapcs_elf_gas.S" ...failed gcc.compile.asm bin.v2/libs/context/build/gcc-10/release/abi-aapcs/address-model-32/architecture-arm/link-static/target-os-android/threading-multi/visibility-hidden/asm/jump_arm_aapcs_elf_gas.o... gcc.compile.asm bin.v2/libs/context/build/gcc-10/release/abi-aapcs/address-model-32/architecture-arm/link-static/target-os-android/threading-multi/visibility-hidden/asm/ontop_arm_aapcs_elf_gas.o ontop_arm_aapcs_elf_gas.S: Assembler messages: ontop_arm_aapcs_elf_gas.S:46: Error: unknown pseudo-op: `.syntax' ontop_arm_aapcs_elf_gas.S:48: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:49: Error: invalid char '{' beginning operand 1 `{lr}' ontop_arm_aapcs_elf_gas.S:50: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:51: Error: invalid char '{' beginning operand 1 `{a1' ontop_arm_aapcs_elf_gas.S:53: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:54: Error: too many memory references for `sub' ontop_arm_aapcs_elf_gas.S:60: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:61: Error: too many memory references for `mov' ontop_arm_aapcs_elf_gas.S:63: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:64: Error: too many memory references for `mov' ontop_arm_aapcs_elf_gas.S:66: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:67: Error: too many memory references for `mov' ontop_arm_aapcs_elf_gas.S:73: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:74: Error: too many memory references for `add' ontop_arm_aapcs_elf_gas.S:76: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:77: Error: invalid char '{' beginning operand 1 `{a1' ontop_arm_aapcs_elf_gas.S:79: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:80: Error: invalid char '[' beginning operand 2 `[a1' ontop_arm_aapcs_elf_gas.S:81: Error: invalid char '[' beginning operand 2 `[a1' ontop_arm_aapcs_elf_gas.S:82: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:83: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:85: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:86: Error: too many memory references for `add' ontop_arm_aapcs_elf_gas.S:88: Error: junk at end of line, first unrecognized character is `@' ontop_arm_aapcs_elf_gas.S:89: Error: no such instruction: `bx a4' ontop_arm_aapcs_elf_gas.S:92: Error: junk at end of line, first unrecognized character is `@'
解决方法
从错误信息看,当前编译过程调用的是主机的g++而非Android交叉编译工具链的汇编器,导致无法识别ARMv7的汇编语法。需要在b2命令中明确指定工具链参数,确保使用交叉编译工具:
- 直接复用容器中已配置的环境变量,修改
b2命令如下:./b2 architecture=arm address-model=32 binary-format=elf abi=aapcs target-os=android \ toolset=gcc \ as=$AS \ ar=$AR \ cc=$CC \ cxx=$CXX - 若上述方式无效,可手动指定交叉工具链的前缀路径(以ARM 32位Android工具链前缀
arm-linux-androideabi-为例):./b2 architecture=arm address-model=32 binary-format=elf abi=aapcs target-os=android \ toolset=gcc \ gcc-as=$(which arm-linux-androideabi-as) \ gcc-ar=$(which arm-linux-androideabi-ar) \ gcc-compiler=$(which arm-linux-androideabi-g++)
另外,Boost的context库对汇编语法兼容性要求较高,需确保工具链版本与Boost版本匹配。若目标设备支持VFP指令集,可尝试将abi=aapcs替换为abi=aapcs-vfp,也可添加--with-context参数单独编译该库验证配置是否生效。
内容的提问来源于stack exchange,提问作者JonasVautherin
相关产品推荐
相关产品推荐

