I have tried many methods and failed( Cygwin + android-ndk, codesourcery, etc..). Jim Ablet told me how to do a cross platform compile for android on a windows machine but it uses a static build which increases the size of the binary significantly. I have about five binaries to package so size matters to me. How do you build a dynamically linked binary which uses libraries from the existing bionic (chopped up glibc) from the phone ?
Thanks
how to build dynamically linked arm binary
Moderators: hgm, Dann Corbit, Harvey Williamson
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
-
Michel
- Posts: 2271
- Joined: Mon Sep 29, 2008 1:50 am
Re: how to build dynamically linked arm binary
I can only say that it is possible since I did it.
The fastest way is to use the android-ndk to generate a gcc toolchain.
The android-ndk includes a script to do this. See e.g. here
http://www.srombauts.fr/android-ndk-r5b ... CHAIN.html
Once you have a gcc toolchain you can use gcc as a cross compiler in
the usual way. Everything will have been set up correctly.
If you really want to torment yourself you can use the standard gcc
but then you need a command line of about half a page.
The fastest way is to use the android-ndk to generate a gcc toolchain.
The android-ndk includes a script to do this. See e.g. here
http://www.srombauts.fr/android-ndk-r5b ... CHAIN.html
Once you have a gcc toolchain you can use gcc as a cross compiler in
the usual way. Everything will have been set up correctly.
If you really want to torment yourself you can use the standard gcc
but then you need a command line of about half a page.
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: how to build dynamically linked arm binary
oh my finally compiled a hello.c dynamically linked. i had to torment myself with codesourcery before but this one with cygwin and ndk is much easier as you said. Exporting paths and taking care of paths with spaces is what I needed. Now I will try projects with larger system library needs.
thanks a lot
thanks a lot
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: how to build dynamically linked arm binary
The method doesn't work for cpp files. If I change from <stdio.h> to <cstdio> it fails to recognize it. I looked in the ndk include folder and can't find cstdio. It shoud be there somewhere I guess. If I just rename the file to hello.cpp and not change the include it works.
-
Michel
- Posts: 2271
- Joined: Mon Sep 29, 2008 1:50 am
Re: how to build dynamically linked arm binary
Did you try invoking g++ instead of gcc?
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: how to build dynamically linked arm binary
Yes I did. But I think you mean arm-linux-androideabi-g++ rather than g++ which is in a similar but different directory. Here is what I did. First cygwin is started with paths of NDK set.
Cygwin starter batch file
Then
The frist run was correct with #include<stdio.h>. The second run fails because it can not find <cstdio>. I think ndk has limited support of c++ accoring to http://stackoverflow.com/questions/2105 ... port-for-c .
But I thought the limit was only for advanced stuff STL, exceptions and RTTI...
Cygwin starter batch file
Code: Select all
@echo off
set SYSROOT=C:/Progra~1/Android/android-ndk-r8/platforms/android-8/arch-arm
set MYGCC=/cygdrive/c/Progra~1/Android/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++
set ARM=%MYGCC% --sysroot=%SYSROOT%
C:
chdir C:\cygwin\bin
bash --login -i
Code: Select all
Daniel@Daniel-PC ~
$ cd "C:\Users\Daniel\Desktop\Hello"
Daniel@Daniel-PC /cygdrive/c/Users/Daniel/Desktop/Hello
$ ls
hello.cpp
Daniel@Daniel-PC /cygdrive/c/Users/Daniel/Desktop/Hello
$ $ARM hello.cpp -o hello
Daniel@Daniel-PC /cygdrive/c/Users/Daniel/Desktop/Hello
$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
Daniel@Daniel-PC /cygdrive/c/Users/Daniel/Desktop/Hello
$ $ARM hello.cpp -o hello
hello.cpp:1:18: error: cstdio: No such file or directory
hello.cpp: In function 'int main(int, char**)':
hello.cpp:3: error: 'printf' was not declared in this scope
Daniel@Daniel-PC /cygdrive/c/Users/Daniel/Desktop/Hello
$
But I thought the limit was only for advanced stuff STL, exceptions and RTTI...
-
Michel
- Posts: 2271
- Joined: Mon Sep 29, 2008 1:50 am
Re: how to build dynamically linked arm binary
I think you did not fully read my suggestion....
You should first generate a gcc-toolchain with the script
After that no path setting whatsoever is required. As far as I can tell c++ is fully supported (I used it to compile your egbb.so).
You should first generate a gcc-toolchain with the script
Code: Select all
android-ndk-r5/build/tools/make-standalone-toolchain.sh --install-dir <whatever> Code: Select all
#include <iostream>
using namespace std;
int main () {
cout << "Hello World!";
return 0;
}Code: Select all
$gcc-android/bin/arm-linux-androideabi-g++ hello.c -ohello
$file hello
hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: how to build dynamically linked arm binary
I used the first method (step 2) of the link you gave. I did not try the second method (step 3) which uses gcc toolchain script. I will try that now but bear in mind I am working on windows and I don't know if the shell scripts would work...
-
Michel
- Posts: 2271
- Joined: Mon Sep 29, 2008 1:50 am
Re: how to build dynamically linked arm binary
I had not realized you were using windows.I will try that now but bear in mind I am working on windows and I don't know if the shell scripts would work..
I think in cygwin shell scripts should work as usual.
-
Daniel Shawul
- Posts: 4185
- Joined: Tue Mar 14, 2006 11:34 am
- Location: Ethiopia
Re: how to build dynamically linked arm binary
Thanks. It works now since this one generated the necesessary c++ headers after I run the sh script ( Runs fine on cygwin too ). Don't know where the cstdio library was in the original ndk package. That must be an auto generated thing which is why the first method worked only for c codes.
Edit I compiled scorpio now. The only obstacle was that -lpthread is not included with the ndk but anyway single cpu is fine too.
Edit I compiled scorpio now. The only obstacle was that -lpthread is not included with the ndk but anyway single cpu is fine too.