레이블이 boost인 게시물을 표시합니다. 모든 게시물 표시
레이블이 boost인 게시물을 표시합니다. 모든 게시물 표시

2014년 9월 25일 목요일

boost build, cross compile for arm

boost library
http://www.boost.org/

[build for linux] 

boost library를 사용할 필요가 있어 빌드함.
linux 상에서의 기본 빌드는 간단하다.

http://www.boost.org/doc/libs/1_51_0/more/getting_started/unix-variants.html#easy-build-and-install

$ ./bootstrap.sh
$ ./b2
$ sudo ./b2 install

이렇게 하면 아래 path에 설치 됨.

headers :  /usr/local/include/boost
libraries : /usr/local/lib

만약 빌드 중 gits/predefs.h 가 없다는 에러가 나오면 gcc-multilib를 설치
http://stackoverflow.com/questions/12591629/gcc-cannot-find-bits-predefs-h-on-i686
sudo apt-get install gcc-multilib

feature.h를 못찾겠다고 하면 아래 include 정보 추가
./b2 include=/usr/include

[cross compile for ARM architecture]

arm linux 용으로 빌드를 할 필요가 있어
cross compile을 하려면 다음과 같이 설정하고 빌드 하면 됨.

bjam cross compilation 설정

boost 폴더/tools/build/v2/user-config.jam  에 다음 정보만 입력
using gcc : arm : arm-none-linux-gnueabi-g++ ;
위 처럼 tool set name : version : invocation command 아니면 option을 입력
arm 용 cross compile 시에는 version 대신 arm을 기입했는데 상관 없는듯.

그리고 세번째 항목에는 컴파일러 빌드 명령과 option을 입력하는게 맞는데
option을 어떻게 설정하는지는 잘 몰라서 여기서 설정하지 않고 b2 실행 시 command line에서 입력 함.

참고로 아래 링크의 QnA에서 compile option을 compileflags 로 기입하는 것을 볼 수 있지만 실제 해봤을 때 boost 빌드에서 먹히지가 않았음.. http://stackoverflow.com/questions/15686972/how-to-change-check-the-compiler-used-by-b2-when-compiling-boost

using gcc : macports :
         full/Path/g++-mp4.8 :
  <compileflags>--sysroot=full/path/to/sysroot
  ;

빌드하면 boost documentation에서 보듯이 toolset과 target을 지정해서 빌드하면 됨.
# On windows box
b2 toolset=gcc-arm target-os=linux
# On Linux box
b2 toolset=gcc-mingw target-os=windows
되지만 아래 설정이 되어 있는지 먼저 확인을 해봐야 한다.

1. user-config.jam에서 설정된 invocation command 경로가 $PATH에 추가 되어 있는지
    추가 되어 있지 않았다면 추가하거나 아니며 user-config.jam에서 full path와 함께 command를 입력해라.
2. cross compile 시 필요한 include 파일이나 library들이 존재하는지
    cross compile tool chain에서 제공하는 include 파일들과 library들이 어디에 있는지 경로를 확인해 두고 관련 에러 시 path를 명시해야 한다.
3. 빌드 에러 시 정확한 메세지 확인을 위해서는 -d+2 (debug message level), -q(error 발생 시 빌드 중지) 옵션을 사용

그래서 나는 일단 다음과 같이 빌드 하였음.

./b2 toolset=gcc-arm target-os=linux  include=/home/ccc/arm-tool-chain/usr/include/ -d+2 -q 

빌드 후 library들은 boost 폴더 내 stage/lib 폴더에 복사된다.

참고로 세부 빌드 옵션 설명은 다음 링크에서 설명하고 있음.
예를 들어 include path 추가는 include, library 형태(.a, .so)는 link, flag 추가는 cxxflags, cflags, linkflags 를 사용..

근데 shared library로 빌드하려니.. gcc 설정이 문제인지 빌드가 안된다.. 포기..

Table 4.2. 
FeatureAllowed valuesNotes
variantdebug,release
linkshared,staticDetermines if Boost.Build creates shared or static libraries
threadingsingle,multiCause the produced binaries to be thread-safe. This requires proper support in the source code itself.
address-model32,64Explicitly request either 32-bit or 64-bit code generation. This typically requires that your compiler is appropriately configured. Please refer to the section called “C++ Compilers” and your compiler documentation in case of problems.
toolset(Depends on configuration)The C++ compiler to use. See the section called “C++ Compilers” for a detailed list.
include(Arbitrary string)Additional include paths for C and C++ compilers.
define(Arbitrary string)Additional macro definitions for C and C++ compilers. The string should be either SYMBOL or SYMBOL=VALUE
cxxflags(Arbitrary string)Custom options to pass to the C++ compiler.
cflags(Arbitrary string)Custom options to pass to the C compiler.
linkflags(Arbitrary string)Custom options to pass to the C++ linker.
runtime-linkshared,staticDetermines if shared or static version of C and C++ runtimes should be used.
If you have more than one version of a given C++ toolset (e.g. configured in user-config.jam, or autodetected, as happens with msvc), you can request the specific version by passing toolset-version as the value of the toolset feature, for example toolset=msvc-8.0.
If a feature has a fixed set of values it can be specified more than once on the command line. In which case, everything will be built several times -- once for each specified value of a feature. For example, if you use
b2 link=static link=shared threading=single threading=multi
Then a total of 4 builds will be performed. For convenience, instead of specifying all requested values of a feature in separate command line elements, you can separate the values with commas, for example:
b2 link=static,shared threading=single,multi
The comma has this special meaning only if the feature has a fixed set of values, so
b2 include=static,shared
is not treated specially.

2013년 3월 27일 수요일

Android NDK를 사용한 boost library 빌드 방법

이전 블로그에서 이전 함 (원본 글 2013/03/27 작성)

[준비물]

- boost for Android의 git repository의 파일들
 . https://github.com/MysticTreeGames/Boost-for-Android
 . git clone 해서 받아도 되고 귀찮으면 zip으로 한꺼번에 받아도 되고

- boost source code, Android NDK
 . boost source code는 boost for Android가 다운로드 받아 준다. 


[boost for android 실행 (Boost source code 다운로드 및 빌드)]

1. boost for build에 명시되어 있는 표에 맞춰서 Andorid NDK 다운로드

Boost for Android

Boost for android is a set of tools to compile the main part of the Boost C++ Libraries for the Android platform.Currently supported boost versions are 1.45.0, 1.48.0, 1.49.0 and 1.53.0.To compile Boost for Android you may use one of the following NDKs:
NDK / boost1.451.481.491.53
r4 customized by Dmitry Moskalchuk aka CrystaX.x
r5 from the official android repository.x
r5 customized by CrystaX.x
r7 customized by CrystaX.xxx
r8 from the official android repository.xxx
r8b from the official android repository.xx
r8c from the official android repository.x
r8d from the official android repository.xx
r8e from the official android repository.xx

* Android NDK 32bit version 사용 필요, build for boost가 인식 못함. 
 . Android NDK의 RELEASE.txt에서 64bit description을 제거해도 toolchaing등이 32bit에 맞춰 설정 되어 있음.

2. build-android 실행

* 다운받은 build for andoid 내 build-android.sh 실행
 . option들 중에는 boost version을 정하는 --boost, 빌드 대상 library를 정하는 --with[out]-libraries 가 있음.

haha@cs-portable:~/source/Boost-for-Android$ ./build-android.sh --help
Usage: build-android.sh [options] <ndk-root>

       Boost For Android
Copyright (C) 2010 Mystic Tree Games

Valid options (defaults are in brackets):

  --help                         Print this help.
  --verbose                      Enable verbose mode.
  --output=<path>                Specify specific log output path (only terminal output by default)
  --boost=<version>              Boost version to be used, one of {1.53.0,1.49.0, 1.48.0, 1.45.0}, default is 1.53.0.
  --clean                        Delete all previously downloaded and built files, then exit.
  --download                     Only download required files and clean up previus build. No build will be performed.
  --with-libraries=<list>        Comma separated list of libraries to build.
  --without-libraries=<list>     Comma separated list of libraries to exclude from the build.

haha@cs-portable:~/source/Boost-for-Android$ ./build-android.sh 
To follow build in another terminal, please use: tail -F /home/haha/source/Boost-for-Android/logs/myst-log-14385.log
Building boost version: 1.53.0
Using AndroidNDKRoot = /home/haha/_program/android-ndk-r8e
Detected Android NDK version 8e
Building with TOOLSET=gcc-androidR8e CXXPATH=/home/haha/_program/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-g++ CXXFLAGS= -L -L -lgcc
Downloading boost 1.53.0 please wait...
Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Resolving garr.dl.sourceforge.net (garr.dl.sourceforge.net)... 193.206.140.34, 2001:760:ffff:b0::34
Connecting to garr.dl.sourceforge.net (garr.dl.sourceforge.net)|193.206.140.34|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 55765258 (53M) [application/octet-stream]
Saving to: `/home/haha/source/Boost-for-Android/boost_1_53_0.tar.bz2'

     0K .......... .......... .......... .......... ..........  0% 46.5K 19m30s
    50K .......... .......... .......... .......... ..........  0% 71.2K 16m6s

* 기본으로는 static library로 빌드가 되며 아래 메세지가 나와도 library들 빌드와 header 복사는 된 상태 임

 . "./build-android.sh: 318: ./build-android.sh: Bad substitution"

* 몇건은 실패하는데.. 사실 system, filesystem, thread, date_time 정도만 있어도 문제는 없어서..
    혹시나 더 필요하다면 좀 찾아봐야 하는데.. 귀찮음..
* 생성된 libraries는 JNI project에서 추가하여 사용하면 되고 만약 so를 사용할 것이라면 Android phone에 deploy하는 것을 확인해야 함.

 ...skipped <p../build/lib>libboost_thread-gcc-mt-1_53.so.1.53.0 for lack of <pbin.v2/libs/thread/build/gcc-androidR8e/release/threading-multi>libboost_thread-gcc-mt-1_53.so.1.53.0...
...skipped <p../build/lib>libboost_thread-gcc-mt-1_53.so for lack of <p../build/lib>libboost_thread-gcc-mt-1_53.so.1.53.0...
...failed updating 6 targets...
...skipped 18 targets...
...updated 10251 targets...
./build-android.sh: 328: ./build-android.sh: Bad substitution
Done!
haha@cs-portable:~/source/Boost-for-Android$ find . -name *.a*
./build/lib/libboost_date_time-gcc-mt-1_53.a
./build/lib/libboost_regex-gcc-mt-1_53.a
./build/lib/libboost_iostreams-gcc-mt-1_53.a
./build/lib/libboost_thread-gcc-mt-1_53.a
./build/lib/libboost_filesystem-gcc-mt-1_53.a
./build/lib/libboost_system-gcc-mt-1_53.a
./build/lib/libboost_program_options-gcc-mt-1_53.a
./build/lib/libboost_signals-gcc-mt-1_53.a




[Android NDK를 사용한 Native 개발 시 참고]
  
* Android NDK 버전 마다 C++ library의 버전 차이로 인한 이슈 존재
Native에서 고급? C++ feature를 사용하는 경우.. 상용화 입장에서는 고생 함.
참고로 boost는 주 빌드 방법은 Android NDK + GNU_STL을 사용하고 RTTI, EXCEPTION feature는 제외하고 컴파일 함.

* NDK에서 지원하는 C++ library들의 조합은 다음과 같다.

    system                   Use the default minimal system C++ runtime library.
    gabi++_static      - Use the GAbi++ runtime as a static library.
    gabi++_shared   - Use the GAbi++ runtime as a shared library.
    stlport_static        - Use the STLport runtime as a static library.
    stlport_shared     - Use the STLport runtime as a shared library.
    gnustl_static        - Use the GNU STL as a static library.
    gnustl_shared      - Use the GNU STL as a shared library.

The capabilities of the various runtimes vary. See this table:

                 C++       C++   Standard
              Exceptions  RTTI    Library
    system        no       no        no
    gabi++       yes      yes        no
    stlport         yes      yes       yes
    gnustl         yes      yes       yes

 . $ANDROID_NDK/doc 내 파일들 참고
   : CPLUSPLUS-SUPPORT.html  NDK-BUILD.html  NDK-GDB.html  NDK-STACK.html

* 팀원들의 NDK의 버전을 통일하는 것이 혹시나 모를 이상항 링크 에러 등을 방지하는데 도움 

* Native library들을 빌드하는 NDK 버전과 Native library들이 사용하는 다른 native library들을 빌드한 NDK 버전을 통일하는 것을 추천

* JNI 빌드할때 모든 빌드 결과물의 arm, thumb mode를 맞춰라. 안 맞을 경우 원인 모를 crash 발생 가능하다.