MacOSXでAndroid向けにC++をクロスコンパイルする
最終的にうまく行ったやりかた
以下のモジュールをインストール。
sudo port install gmp sudo port install mpfr sudo port install mpc sudo port install ppl sudo port install arm-none-linux-gnueabi-binutils sudo port install arm-none-linux-gnueabi-gcc
クロスコンパイルする。
arm-none-linux-gnueabi-g++ --static -o helloworld ./helloworld.cpp
helloworld.cppの中身。
#include <stdio.h> int main() { printf("Hello World!\n"); return 0; }
fileコマンドで見てみる。
file helloworld helloworld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.4.17, not stripped
実機に転送
adb push helloworld /data/tmp
※実機の「/data/tmp」はあらかじめ作ってあり、ユーザーに書き込み権限があります。
実機で実行
adb shell $ cd /data/tmp $ ./sample Hello World!
ふむ。
参考にしたURL
- http://notepad4yu.wordpress.com/2009/05/31/mac-os-x-%E7%94%A8-arm-%E3%82%AF%E3%83%AD%E3%82%B9%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%A9%E3%81%A7-sheevaplug-%E3%81%AE%E3%82%AB%E3%83%BC%E3%83%8D%E3%83%AB%E3%82%92%E3%82%B3%E3%83%B3%E3%83%91/
- http://r-mix64.ddo.jp/?p=177
- http://www.adamrocker.com/blog/191/c_native_executable_file_on_android.html
- http://www.adamrocker.com/blog/190/run_android_native_file_result_in_segmentation_fault_on_mac_osx.html