8

I am trying to use boost library with Android ndk in Eclipse with Windows. I tried to follow this tutorial

I am stuck in the step with "bjam" command in cygwin.

bjam --without-python --without-serialization toolset=gcc-android4.4.3 link=static runtime-link=static target-os=linux --stagedir=android

Error: bjam command not found.

What is bjam? Also I used the boost 1.53 along ndk r8e. Can someone help me with this please?

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
user2508941
  • 245
  • 3
  • 11

1 Answers1

18

Android NDK is no longer dependent on Cygwin, so you can build Boost with the NDK from within Windows command prompt (cmd).

In order to make Boost.Build find the NDK, edit boost\tools\build\v2\user-config.jam file and append the following text:

import os ;

androidNDKRoot = C:/android-ndk-r8e ; # put the relevant path
 using gcc : android :
     $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-g++ :
     <compileflags>--sysroot=$(androidNDKRoot)/platforms/android-9/arch-arm
     <compileflags>-mthumb
     <compileflags>-Os
     <compileflags>-fno-strict-aliasing
     <compileflags>-O2
     <compileflags>-DNDEBUG
     <compileflags>-g
     <compileflags>-lstdc++
     <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/include
     <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/include
     <compileflags>-D__GLIBC__
     <compileflags>-D_GLIBCXX__PTHREADS
     <compileflags>-D__arm__
     <compileflags>-D_REENTRANT
     <archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-ar
     <ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-ranlib
         ;

Certainly, instead of c:/android-ndk-r8e you have to put the right location of the NDK on your PC.

Besides, you can select more recent platform API, instead of android-9.

Also note that the NDK supplies several tool-chains, and the above settings point to gcc-4.7. If you prefer to build boost with some other tool-chain, change arm-linux-androideabi-4.7 to the relevant path.

After you've put the configuration in user-config.jam, open cmd, cd to the directory where Boost resides, and invoke bootstrap. Then invoke b2 like this (for example):

b2 --without-python --without-serialization threading=multi link=static runtime-link=static toolset=gcc-android target-os=linux threadapi=pthread --stagedir=android stage

UPDATE: As of 11/2015, older NDK toolchains seem to have issues with the newer Boost versions, causing compiler crash, so consider using a more recent compiler. To do this, just change every 4.7 occurrence in the above script to 4.9. Also, it's worth compiling with a more recent Android API (eg. andoroid-9 -> andoroid-16 or so).

Igor R.
  • 14,716
  • 2
  • 49
  • 83
  • D:\android_ndk_with_boost\android-ndk-r8e\sources\boost_1_53_0\tools\build\v2>b2 --without-python --without-serialization threading=multi link=static runtime-li nk=static toolset=gcc-android4.6 target-os=linux threadapi=pthread --stagedir=an droid D:/android_ndk_with_boost/android-ndk-r8e/sources/boost_1_53_0/tools/build/v2/to ols\gcc.jam:78: in gcc.init from module gcc error: toolset gcc initialization: error: provided command 'D:/android_ndk_with_boost/android-ndk-r8e/toolchains/ar m-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++' not foun d – user2508941 Jul 16 '13 at 09:59
  • @user2508941 What is "toolset=gcc-android4.6"? How did you define that in your user-config.jam? (Use pastebin.com or similar site to put errors.) – Igor R. Jul 16 '13 at 10:03
  • Is that a syntax error... Coz we have in android ndk r8e (4.4.3 4.6 and 4.7)... changed the 4.7 to 4.6 in the code you gave me dude.. – user2508941 Jul 16 '13 at 10:13
  • Path is the same except for the change in the 4.7 to 4.6 – user2508941 Jul 16 '13 at 10:15
  • @user2508941 First of all, I'd recommend you to try and use the config file I posted as is, and invoke `b2` as in my example. You can't set "toolset=gcc-android4.6" because there's no "android4.6" version in `using` section, so either keep it "toolset=gcc-android" or learn Boost.Build syntax: http://www.boost.org/boost-build2/doc/html/bbv2/overview/configuration.html – Igor R. Jul 16 '13 at 10:18
  • @user2508941 As for using gcc4.6 toolchain, you can do this by changing every occurrence of '4.7` to '4.6' in the above user-config.jam. I believe, `gnu-libstdc++/4.7` path also has to be changed to `gnu-libstdc++/4.6`. – Igor R. Jul 16 '13 at 10:20
  • Cool... Did that too.. Except for the 4.6 to be changed to 4.7, the error remains the same dude – user2508941 Jul 16 '13 at 10:22
  • @user2508941 Post your exact user-config.jam, `b2` line and the output to pastebin.com. – Igor R. Jul 16 '13 at 10:23
  • http://pastebin.com/HJ7GSQNW contains the error and user-config.jam .. the command is b2 --without-python --without-serialization threading=multi link=static runtime-link=static toolset=gcc-android target-os=linux threadapi=pthread --stagedir=android... – user2508941 Jul 16 '13 at 10:33
  • @user2508941 Does the following path exist on your PC 'D:/android_ndk_with_boost/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/` ? – Igor R. Jul 16 '13 at 10:53
  • Yes dude.... got that one right it was windows-x86_64... After changing that I got the following error... http://pastebin.com/eByh5cqg – user2508941 Jul 16 '13 at 11:23
  • @user2508941 So, you actually build for x64? Then I'm afraid I hardly can assist you. Anyway, try removing "threadapi=pthread" option from `b2` line. – Igor R. Jul 16 '13 at 11:30
  • Cool... You rock dude!!!! I got the message that 311 targets have been updated... Could you tell me why I had to remove that option?? – user2508941 Jul 16 '13 at 11:47
  • @user2508941 For some reason, feature wasn't found. Did it build Boost.Thread at all? You can try adding it explicitly: `--with-thread` and putting `threadapi=pthread` back... – Igor R. Jul 16 '13 at 11:59
  • Nope I got the same issue ... In http://pastebin.com/gXuUV8Ea you can find the result... I hope the command is what you meant – user2508941 Jul 16 '13 at 12:23
  • Um, why didn't you build Boost.Serialization? Is there any problem? – ikh Mar 27 '14 at 11:26
  • @ikh Older NDK versions didn't implement `wchar_t`-related routines, that was the problem. I don't know what the status of this issue is in the recent NDK. – Igor R. Mar 27 '14 at 13:34
  • I use android-ndk-r9d. Boost.Serialization seems to be built successfully, but Boost.Context cannot be built: `'armasm' is not recognized as an internal or external command, operable program or batch file.` – ikh Mar 28 '14 at 10:55
  • @ikh so they support now wide-char, great news. As for `Context`, I guess the NDK just doesn't have `armasm` util. – Igor R. Mar 28 '14 at 15:35
  • @IgorR. ummm.. I hope we can use all boost feature sometime > – ikh Mar 28 '14 at 23:02
  • When I try this is I get an error: `boost_1_55_0/tools/build/v2/kernel\modules.jam:258: in modules.import from module modules error: When loading multiple modules, no specific rules or renaming is allowed` It seems to not like the fact that there are a bunch of compile options set in user_config.jam. – dadude999 Sep 10 '15 at 20:23
  • Turns out I had space in the path to my NDK, and even putting it in quotes didn't work. Also, the `androidNDKRoot` variable didn't seem to get dereferenced properly, so I just copy-pasted the actual path instead. – dadude999 Sep 10 '15 at 22:00
  • @dadude999 Make sure the syntax is correct (eg. pay attention to the space before semicolon). – Igor R. Sep 11 '15 at 14:08
  • @Tomáš Zato It's your program that crashes NDK's C++ compiler (a lot of complex templates?). Try using a more recent NDK toolchain, it might be less buggy. – Igor R. Nov 10 '15 at 17:37
  • @IgorR. Wow you must be kidding me. What my program? I was compiling **boost** with it, not my program. Also I downloaded NDK in Friday, so I don't think it's outdated. – Tomáš Zato Nov 11 '15 at 09:39
  • @Tomáš Zato Ah, sorry, I thought you use similar script to compile your own apps with boost.build. Anyway, the recommendation is still the same: use more recent toolchain, instead of legacy gcc4.7 (which is supplied with new NDKs for backward compatibility only). – Igor R. Nov 11 '15 at 16:49