1

I am compiling a simple program with the Android NDK Linux build on Ubuntu Linux 10.0.4.

//no includes!!!
int main()
{   
    int a = 1, b = 2, c = -1;
    return a + b + c - ( a + b + c);

}

When I run this bash script for gcc,

bin='/media/sdb/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin'
rm -r ./obj/*.* 
    $bin/arm-linux-androideabi-gcc -c ./main.c -o ./obj/main.o 
    $bin/arm-linux-androideabi-gcc ./obj/main.o -o ./obj/main.exe 

the output of gcc gives a message from ld (arm-linux-androideabi-ld) that it terminated as 7 (second comma-delimited is ARM) signal.

This simple program won't even compile on Linux, please help!

T. Webster
  • 9,605
  • 6
  • 67
  • 94
  • main.o is an already executable binary created by first command. I don't know what you are trying to achieve with second one. – auselen Feb 04 '13 at 08:03
  • I was not aware that the main.o file was executable. Unrelated, for robustness in the case of referenced libs (.a) files. It seems to require first compile ./main.c then ./obj/main.o [with any includes] – T. Webster Feb 04 '13 at 08:33
  • sorry my mistake, I saw it as (without -c) $bin/arm-linux-androideabi-gcc ./main.c -o ./obj/main.o – auselen Feb 04 '13 at 08:34
  • can you print what's the exact message with ld, I never saw such one before. – auselen Feb 04 '13 at 08:46
  • 1
    my best guess is your compilations is triggering another ld, instead of the one from ndk. – auselen Feb 04 '13 at 09:00
  • 1
    by the way don't use tilde `~` anywhere in the paths. – auselen Feb 04 '13 at 09:05

1 Answers1

1

I have installed static tool chain in ubuntu 12.4

sudo apt-get install gcc-arm-linux-gnueabi  // install this toolchain 

arm-linux-gnueabi-gcc -static -o main.exe main.c  // this way compile ur binary

copy through adb in android machine and run

./main.exe

this works in my android mobile.

Edit:

for 10.04

   sudo add-apt-repository ppa:linaro-maintainers/toolchain
    sudo apt-get update
    sudo apt-get install gcc-arm-linux-gnueabi

Edit2: Its static compilation here it doesnt use bionic code and it include libraries by copying them into the ELF.

If you want to dynamic compilation or want to depend on bionic code then use

$NDK/docs/STANDALONE-TOOLCHAIN.html https://android.googlesource.com/platform/ndk/+/master/docs/STANDALONE-TOOLCHAIN.html

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
  • Couldn't find package gcc-arm-linux-gnueabi http://askubuntu.com/questions/123835/gcc-arm-linux-gnueabi-package-not-found-on-10-04-lts-lucid which of these work? http://packages.ubuntu.com/search?keywords=gcc-arm-linux-gnueabi – T. Webster Feb 04 '13 at 07:28
  • oh sorry i am on ubuntu 12.04 – Jeegar Patel Feb 04 '13 at 07:31
  • I don't know what you mean by static toolchain but android has its own runtime libraries (bionic) so while you can certainly get runnable executables, it's a much better idea to use toolchain from ndk. – auselen Feb 04 '13 at 08:05
  • 1
    @auselen static means its not using bionic code. binary generated using this way has larger size then dynamic build or ndk build. For dyanic build i put my code in android source tree and compile so it uses binoic code. I dont know how to do that with NDK.. – Jeegar Patel Feb 04 '13 at 08:07
  • so it is not the toolchain that is static, but your compilation. you can create a statically component with ndk just the way you do with another gcc toolchain. if you are interested read about standalone part in NDK docs. – auselen Feb 04 '13 at 08:13
  • @Mr.32 to me that's impressive you have done this without needing the NDK. I still wonder why the NDK's gcc doesn't work though on Ubuntu. Also, I'm not *that* familiar with gcc (too much .NET), but does `-static` mean you include libraries by *copy*ing them into the ELF, instead of, "dynamically" linking the libs (sharing them) in at link time? I can ask it another question (more points!) – T. Webster Feb 04 '13 at 08:15
  • @auselen do u have link for that? If yes than please post it so we can edit answer better way – Jeegar Patel Feb 04 '13 at 08:16
  • 1
    @T.Webster yes static means it include libraries by copying them into the ELF.NDK shoud do it but i dont know why its not doing. Your error says that its missing bionic component. – Jeegar Patel Feb 04 '13 at 08:19
  • $NDK/docs/STANDALONE-TOOLCHAIN.html https://android.googlesource.com/platform/ndk/+/master/docs/STANDALONE-TOOLCHAIN.html – auselen Feb 04 '13 at 08:32
  • I read the toolchain but `export CC="$NDK/toolchains//prebuilt//bin/gcc --sysroot=$SYSROOT" $CC -o foo.o -c foo.c` did not work. Same signal 7 error from `ld`. I would have just compiled thru the default NDK toolchain, with ndk-build, but I still Same signal 7 error from `ld`. This is why I wanted to look at the compiling-linking process closely to understand what is going on, since the errors made little sense. – T. Webster Feb 04 '13 at 08:39
  • You usually don't use the .exe suffix for android programs. .exe is only used for Windows PW executables. – fuz Feb 04 '13 at 10:33
  • @FUZxxl i have just used to match op's question. Because he was confuse in object file and in executable binary – Jeegar Patel Feb 04 '13 at 10:48