[boost] Building Boost (1.60) with Clang and NDK

679 views
Skip to first unread message

Fatih Kıralioğlu

unread,
Jan 5, 2016, 7:10:59 PM1/5/16
to bo...@lists.boost.org
Has anyone built the Boost with Clang and NDK other than CryStax? If so, can you post the related config.jam and build script? I have handled gcc build but clang is very very chalnllenging and no one including the guys in Stackoverflow could answer it.

Many Thanks.


Fatih

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Dmitry Moskalchuk

unread,
Jan 6, 2016, 4:40:51 AM1/6/16
to bo...@lists.boost.org
On 05/01/16 23:06, Fatih Kıralioğlu wrote:
> Has anyone built the Boost with Clang and NDK other than CryStax? If so, can you post the related config.jam and build script? I have handled gcc build but clang is very very chalnllenging and no one including the guys in Stackoverflow could answer it.

Hi Fatih,

We're building Boost libraries continuously with clang from CrystaX NDK.
This is not much straightforward, but nothing magical. You can find our
build script here:
https://github.com/crystax/android-platform-ndk/blob/master/build/tools/build-boost.sh.

Here is example how we build it with clang-3.7:

$ ./build/tools/build-boost.sh --abis=armeabi-v7a,x86 --version=1.60.0
--stdlibs=llvm-3.7 $BOOST_DIR

Here BOOST_DIR is directory containing folders named '1.59.0', '1.60.0',
etc.

This script will not work "as is" with Google's NDK due to many
limitations of the last one, but anyway, looking into script's internals
can help understand how to do that.

Also, please take into account that many Boost libraries just could not
be built with Google's NDK (those who requires good support from
underlying libraries such as libc; language-only libraries like
Boost.SmartPtr should work).

--
Dmitry Moskalchuk


signature.asc

Niall Douglas

unread,
Jan 6, 2016, 6:15:21 AM1/6/16
to bo...@lists.boost.org
On 5 Jan 2016 at 20:06, Fatih Kıralioğlu wrote:

> Has anyone built the Boost with Clang and NDK other than CryStax? If so,
> can you post the related config.jam and build script? I have handled gcc
> build but clang is very very chalnllenging and no one including the guys
> in Stackoverflow could answer it.

Boost.Thread is built nightly on the vanilla Android NDK with clang
and has been for at least a year now. Boost.Thread drags in a lot of
Boost with it, so I would expect most of the rest of Boost to also
work.

The build config is utterly standard, simply target-os=android and
you use the arm-linux-androideabi-clang++ compiler from the
toolchain/android-5.0/clang35/bin directory. Nothing magic nor
special. This is why I didn't reply to your SO post, as a quick bit
of searching this list or even stackoverflow would have yielded this
answer.

Niall

--
ned Productions Limited Consulting
http://www.nedproductions.biz/
http://ie.linkedin.com/in/nialldouglas/


Ben Pope

unread,
Jan 6, 2016, 12:06:39 PM1/6/16
to bo...@lists.boost.org
On Wednesday, January 06, 2016 04:06 AM, Fatih Kıralioğlu wrote:
> Has anyone built the Boost with Clang and NDK other than CryStax? If so, can you post the related config.jam and build script? I have handled gcc build but clang is very very chalnllenging and no one including the guys in Stackoverflow could answer it.

I haven't noticed any problems building boost for Android with the NDK,
I honestly have no idea why I see so many people asking how to do it, or
patch sets or whatever.

I'm using gcc-4.9 and std=c++14 on linux x64 targeting armv7. I package
the toolset I want (android 15, gcc-4.9) and pass that sysroot in the
CXXFLAGS, I tend not to interfere with the build system of boost or
android very much, preferring to drive everything from cmake (for my own
projects).

What problems have you seen?

The NDK is moving entirely to clang, the next release will see gcc
deprecated, so I'll have to have a play with moving over to clang, but
in my experience, everything I do works equally well on clang for armv7,
armv8 and x64.

The only problem I remember having is thread locals on iOS targets, but
my memory is short, and it only takes a few lines of code to emulate
that for most purposes.

If you explain what problems you've seen, which libraries, toolsets and
command lines, perhaps you'll trigger a memory of a problem I've solved.

I can give you more details of my configuration on the weekend, if required.

As a sidenote, I'm hoping to bring up a boost/clang/linux/armv8 build
bot if and when my Pine64 arrives and I get Ubuntu/Debian running on it
(by April if all goes well). I have no idea how quickly it will cycle
though, my current x64 tests take around 16 hours for gcc-4.9, gcc-5.2
and clang-3.7, I'll probably have to drop gcc-4.9. I had to give up on
my regular sanitizer builds on x64 as they just take too long and there
seemed to be very little interest. Unfortunately I don't have dedicated
machines to run the tests.

Ben

Fatih Kıralioğlu

unread,
Jan 7, 2016, 6:51:00 AM1/7/16
to bo...@lists.boost.org
Ok, I am sharing my build.bat user-config-android.jam file below, from the outputs, clang is using mingw headers, for clang build, is mingw headers really necessary?

build.bat:

set CXXFLAGS="-I%ANDROID_NDK%/platforms/android-9/arch-arm/usr/include -I%ANDROID_NDK%/sources/cxx-stl/gnu-libstdc++/4.9/include -I%ANDROID_NDK%/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include"
set TOOLSET=gcc-android

b2 --toolset=%TOOLSET% --user-config=./user-config-android.jam cxxflags=%CXXFLAGS% threadapi=pthread --prefix=..\boost_android_arm --builddir=./ target-os=linux --with-date_time --with-filesystem --with-regex --with-log define=BOOST_FILESYSTEM_VERSION=3 --with-program_options --with-signals --with-system --with-thread link=static runtime-link=shared threading=multi install

user-config-android.jam:

androidNDKRoot = android-ndk-r10e ; # put the relevant path
using clang : android :
$(androidNDKRoot)/toolchains/llvm-3.6/prebuilt/windows-x86_64/bin/clang++ :
<compileflags>--sysroot=$(androidNDKRoot)/platforms/android-21/arch-arm
<compileflags>-Os
<compileflags>-fno-strict-aliasing
<compileflags>-O2
<compileflags>-DNDEBUG
<compileflags>-g
<compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/include
<compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include
<compileflags>-D__GLIBC__
<compileflags>-D__ANDROID__
<compileflags>-D_GLIBCXX__PTHREADS
<compileflags>-D__arm__
<compileflags>-D_REENTRANT

And I'am getting this error:

g++: error: unrecognized command line option '-stdlib=libc++'
clang++.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

"android-ndk-r10e/toolchains/llvm-3.6/prebuilt/windows-x86_64/bin/clang++" -o "bin.v2\libs\date_time\build\clang-linux-andr
oid\release\target-os-android\threadapi-pthread\threading-multi\libboost_date_time-clang-mt-1_60.so.1.60.0" -Wl,-soname -Wl,libboost_date_time-clang-m
t-1_60.so.1.60.0 -shared -Wl,--start-group "bin.v2\libs\date_time\build\clang-linux-android\release\target-os-android\threadapi-pthread\threading-mult
i\gregorian\greg_month.o" "bin.v2\libs\date_time\build\clang-linux-android\release\target-os-android\threadapi-pthread\threading-multi\gregorian\greg_
weekday.o" "bin.v2\libs\date_time\build\clang-linux-android\release\target-os-android\threadapi-pthread\threading-multi\gregorian\date_generators.o"
-Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -stdlib=libc++ -lc++_shared -Landroid-ndk-r10e/sources/cxx-stl/llvm-libc++/libs/ar
meabi

...failed clang-linux.link.dll bin.v2\libs\date_time\build\clang-linux-android\release\target-os-android\threadapi-pthread\threading-multi\libboost_da
te_time-clang-mt-1_60.so.1.60.0...
...skipped <p..\boost_android_arm\lib>libboost_date_time-clang-mt-1_60.so.1.60.0 for lack of <pbin.v2\libs\date_time\build\clang-linux-android\release
\target-os-android\threadapi-pthread\threading-multi>libboost_date_time-clang-mt-1_60.so.1.60.0...
clang-linux.compile.c++.without-pth bin.v2\libs\system\build\clang-linux-android\release\target-os-android\threadapi-pthread\threading-multi\error_cod
e.o
In file included from libs\system\src\error_code.cpp:16:
In file included from .\boost/system/error_code.hpp:19:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include\ostream:38:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include\ios:42:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include\bits/ios_base.h:39:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include\ext/atomicity.h:35:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include\bits/gthr.h:148:
In file included from android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include\bits/gthr-default.h:48:
android-ndk-r10e/platforms/android-21/arch-arm/usr/include\pthread.h:164:58: error: unknown type name 'clockid_t'; did you mean '
clock_t'?
int pthread_condattr_getclock(const pthread_condattr_t*, clockid_t*) __nonnull((1, 2));
^
c:/mingw/include\time.h:71:14: note: 'clock_t' declared here
typedef long clock_t;

Fatih KIRALİOĞLU
R&D Engineer
fatih.ki...@sestek.com
www.sestek.com

________________________________________
Gönderen: Fatih Kıralioğlu
Gönderildi: 6 Ocak 2016 Çarşamba 21:13
Kime: bo...@lists.boost.org
Konu: Ynt: [boost] Building Boost (1.60) with Clang and NDK

Thanks for the responses,

The last error I got is:

"In file included from libs\date_time\src\gregorian\greg_weekday.cpp:16:
In file included from libs\date_time\src\gregorian/greg_names.hpp:14:
In file included from .\boost/date_time/gregorian/greg_month.hpp:14:
In file included from .\boost/shared_ptr.hpp:17:
In file included from .\boost/smart_ptr/shared_ptr.hpp:35:
In file included from .\boost/smart_ptr/detail/spinlock_pool.hpp:25:
In file included from .\boost/smart_ptr/detail/spinlock.hpp:47:
In file included from .\boost/smart_ptr/detail/spinlock_gcc_arm.hpp:12:
In file included from .\boost/smart_ptr/detail/yield_k.hpp:28:
In file included from .\boost/predef.h:20:
In file included from .\boost/predef/hardware.h:14:
.\boost/predef/hardware/simd.h:77:5: error: "Multiple SIMD architectures detecte
d, this cannot happen!"
# error "Multiple SIMD architectures detected, this cannot happen!"

"
I have also installed and set it as an include dir for b2.exe to use clang and i got the error above

fatih

________________________________________
Gönderen: Boost <boost-...@lists.boost.org> adına Ben Pope <benp...@gmail.com>
Gönderildi: 6 Ocak 2016 Çarşamba 19:06
Kime: bo...@lists.boost.org
Konu: Re: [boost] Building Boost (1.60) with Clang and NDK

Ben Pope

unread,
Jan 7, 2016, 8:07:40 AM1/7/16
to bo...@lists.boost.org
On Thursday, January 07, 2016 02:21 PM, Fatih Kıralioğlu wrote:
> Ok, I am sharing my build.bat user-config-android.jam file below, from the outputs, clang is using mingw headers, for clang build, is mingw headers really necessary?
>
> build.bat:
>
> set CXXFLAGS="-I%ANDROID_NDK%/platforms/android-9/arch-arm/usr/include -I%ANDROID_NDK%/sources/cxx-stl/gnu-libstdc++/4.9/include -I%ANDROID_NDK%/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include"
> set TOOLSET=gcc-android
>
> b2 --toolset=%TOOLSET% --user-config=./user-config-android.jam cxxflags=%CXXFLAGS% threadapi=pthread --prefix=..\boost_android_arm --builddir=./ target-os=linux --with-date_time --with-filesystem --with-regex --with-log define=BOOST_FILESYSTEM_VERSION=3 --with-program_options --with-signals --with-system --with-thread link=static runtime-link=shared threading=multi install
>
> user-config-android.jam:
>
> androidNDKRoot = android-ndk-r10e ; # put the relevant path

I think you need to put the relevant path there, it should be an
absolute path.

> using clang : android :

This toolset is called clang-android, but you told b2 to use gcc-android.

> $(androidNDKRoot)/toolchains/llvm-3.6/prebuilt/windows-x86_64/bin/clang++ :
> <compileflags>--sysroot=$(androidNDKRoot)/platforms/android-21/arch-arm
> <compileflags>-Os

-Os will be ignored because you specified -O2 below.

> <compileflags>-fno-strict-aliasing
> <compileflags>-O2
> <compileflags>-DNDEBUG
> <compileflags>-g
> <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/include
> <compileflags>-I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include

Remove the above two lines, since you want to use libc++, not libstdc++.
If clang can't find the libc++ headers, then specify the path to libc++.

> <compileflags>-D__GLIBC__
> <compileflags>-D__ANDROID__
> <compileflags>-D_GLIBCXX__PTHREADS
> <compileflags>-D__arm__
> <compileflags>-D_REENTRANT

Your CXXFLAGS also specify flags for include paths for libstdc++, and
platforms/android-9, but your toolset specifies the sysroot as
platforms/android-21.

You should try invoking b2 again with the correct toolset name and
without any CXXFLAGS, since the toolset specifies them.

Reply all
Reply to author
Forward
0 new messages