moritz-wundke / Boost-for-Android

Android port of Boost C++ Libraries
1k stars 482 forks source link

Unable to build for armv7a-android on macOS #138

Open jonmcclung opened 6 years ago

jonmcclung commented 6 years ago

I have been struggling with this for a few days now, and I'd really appreciate some help. I am building on macOS 10.12.5 and my target is armv7a android with NDK r17b using clang/llvm, not gcc. I have gotten a number of errors, and it seems like the only way to make one go away is to generate another. My error does seem to be related to this StackOverflow post.

Here are the steps I have followed:

  1. git clone https://github.com/moritz-wundke/Boost-for-Android.git
  2. set the contents of user-config-boost-1_67_0-armeabi-v7a.jam to
    <ranlib>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(PlatformOS)-x86_64/bin/arm-linux-androideabi-ranlib
    <compileflags>-gcc-toolchain
    <compileflags>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(PlatformOS)-x86_64
    <compileflags>-target
    <compileflags>armv7-none-linux-androideabi
    <compileflags>-march=armv7-a
    <compileflags>-mfloat-abi=softfp
    <compileflags>-mfpu=vfpv3-d16
    <compileflags>-mthumb
    <compileflags>-fpic
    <compileflags>-fno-integrated-as
    <compileflags>--sysroot
    <compileflags>$(AndroidNDKRoot)/sysroot
    <compileflags>-isystem
    <compileflags>$(AndroidNDKRoot)/sysroot/usr/include/arm-linux-androideabi
    <compileflags>-D__ANDROID_API__=15

    per #135

  3. 
    export CXXFLAGS="-std=c++11"

./build-android.sh $ANDROID_NDK_ROOT --with-libraries=thread,filesystem,date_time,system,atomic --arch=armeabi-v7a


At this point I get the following errors:

---------------

Build using NDK

---------------

Building boost for android for armeabi-v7a Adding pathname: /Users/jonmcclung/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:70: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/aarch64-linux-android-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:107: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:149: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:191: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/mips64el-linux-android-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:229: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/mips64el-linux-android-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:267: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/x86-4.9/prebuilt/${PlatformOS}-x86_64 /Users/jonmcclung/Downloads/Boost-for-Android/boost_1_67_0/tools/build/src/user-config.jam:305: Unescaped special character in argument $(AndroidNDKRoot)/toolchains/x86_64-4.9/prebuilt/${PlatformOS}-x86_64

The following warning, once for each library:

warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: warning for library: ../build/build/armeabi-v7a/boost/bin.v2/libs/date_time/build/clang-darwin-armeabiv7a/release/link-static/target-os-android/threading-multi/libboost_date_time-clang-darwin-mt-a32-1_67.a the table of contents is empty (no object file members in the library define global symbols)


4. I try to build my project, but get the following error, once for each library:

/Users/jonmcclung/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: boost_atomic-clang-darwin-mt-a32-1_67: no archive symbol table (run ranlib)


5. So I try to manually call ranlib on each library, but get this:
`bfd plugin: LLVM gold plugin has failed to create LTO module: The end of the file was unexpectedly encountered`

I find this very surprising, because I have basically just followed the default script, only adding in `-std=c++11` because I was getting warnings about things only being in C++11, and only compiling particular libraries and only for a particular platform. Is anyone else able to build the same host and target?
jonmcclung commented 6 years ago

FWIW, I think that the "unescaped special character" can be solved by applying the following regex to jam files: <compileflags>(.*)\$\{PlatformOS\}(.*) -> <compileflags>"$1${PlatformOS}$2"

RGPaul commented 6 years ago

Have you tried the PR 135. With this Version I could compile Boost on macOS.

jonmcclung commented 6 years ago

@Manromen I did try that PR, yes. Ultimately I just ended up using the prebuilt libraries from https://github.com/dec1/Boost-for-Android

jonmcclung commented 6 years ago

For anyone who came here because of the same problem:

The prebuilt libraries I linked to above did not end up working in the long run. I suspect they used a different version of the STL than me, but I can't be sure. What I ultimately did to get it working was create a Ubuntu virtual machine and do everything in there. I still had to perform many of the fixes from #135 as well as the fix I mentioned about "unescaped special character," but was ultimately able to get them working.

Invincibl-e commented 5 years ago

For anyone who came here because of the same problem:

The prebuilt libraries I linked to above did not end up working in the long run. I suspect they used a different version of the STL than me, but I can't be sure. What I ultimately did to get it working was create a Ubuntu virtual machine and do everything in there. I still had to perform many of the fixes from #135 as well as the fix I mentioned about "unescaped special character," but was ultimately able to get them working.

I have the same problem, and I open another issue in yesterday.Linker to boost::filesystem error I just ended up using the prebuilt libraries too. I hope that you can search it with google, don't upset about it for 4 hours.

RGPaul commented 5 years ago

I have a working travis CI that builds this repo (a fork). Maybe this will help you: https://travis-ci.org/Manromen/Boost-for-Android

There are also prebuild libraries at the fork you could give a try: https://github.com/Manromen/Boost-for-Android/releases