I have a Linux system and an old Nexus 4 phone. I am trying to compile a C application to run on it. Normally, when I compile C applications for other phones, I can simply use
aarch64-linux-gnu-gcc -static main.c
However, the Nexus 4 is old and does not support 64-bit executables
/system/bin/sh: /data/local/tmp/a.out: not executable: 64-bit ELF file
How can I compile a 32 bit application? The compiler does not regognize the -m32 flag
aarch64-linux-gnu-gcc: error: unrecognized command line option '-m32'
I also tried compiling my own cross-compiler using ct-ng, and explicitly enable there 32-bit support, but it did not help.
Can anyone help me please?
Related
Is it possible? I can ran 64-bit ELF file (pandoc) on 32-bit OS (Android 13) and 64-bit processor Samsung Exynos 850. What is happaning?
~ $ uname -m
armv8l
Screenshot
Just want to ran pandoc on my mobile phone. I know that i have 32 bit os, so i want to install 32 bit version of pandoc. There is no 32 bit pandoc in termux repositories. So i just add aarch64 repository and install it. I think that pandoc can ran because it staticly builded, and there is no library dependencies. Am i right?
I want to compile some C code manually in order to run it on Android. The C code can be as simple as this hello world program:
#include<stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
The result should be an executable binary file, which I can run with adb like this:
adb push exename /data/local/tmp
adb shell chmod 777 /data/local/tmp
adb shell /data/local/tmp
I am able to create such an executable with Android Studio and the NDK. To better understand the compiling process I want to know how I can manually compile the code with the command line. I know that there are different ABIs that are compiled with different tools, but the process should still be the same.
I am pretty sure it is possible as the NDK includes multiple executables like aarch64-linux-android-as, which allows me to compile Assembly to an executable. Unfortunately, I could not find any documentation of all tools included in the NDK in order to find out which is the correct tool myself.
The question now is if someone knows which tools of the NDK I have to use in order to create an executable from my provided C code. If the process for compiling multiple .c files into one binary is different from gcc I would also appreciate the process of compiling multiple files.
Thank you very much in advance!
~/Library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-linux-android21 helloworld.c -o helloworld
In order to run the bluetooth C program on my ubuntu desktop I installed the libbluetooth-dev using
sudo apt-get install libbluetooth-dev
Then I compiled the code with
gcc -o simplescan simplescan.c -lbluetooth
and it executed just fine. However when I tried to cross compiled it for Android using
arm-linux-gnueabi-gcc -o simplescan simplescan.c -lbluetooth
It gave me the error
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lbluetooth
collect2: error: ld returned 1 exit status
I noticed there was similar post here: Bluetooth programming in Linux - cross compiler issue
But seems like it didn't give a solution, I am still confused how to install the libbluetooth-dev support for the cross compiler.
You cannot link the libbluetooth library that was compiled for a different architecture.
You need to build the libbluetooth library for the architecture your application will be build for.
I got similar to this problem: Android Studio 64-bit ERROR: 32-bit Linux Android emulator binaries are DEPRECATED
I run android studio 2.1.1 on Gentoo Linux/amd64,
and when I try to run emulator of android android studio give me error:
/home/user/Android/Sdk/tools/emulator -netdelay none -netspeed full
-avd Nexus_5X_API_23 ERROR: 32-bit Linux Android emulator binaries are DEPRECATED, to use them
you will have to do at least one of the following:
- Use the '-force-32bit' option when invoking 'emulator'.
- Set ANDROID_EMULATOR_FORCE_32BIT to 'true' in your environment.
Either one will allow you to use the 32-bit binaries, but please be
aware that these will disappear in a future Android SDK release.
Consider moving to a 64-bit Linux system before that happens.
But
$ file /home/user/Android/Sdk/tools/emulator
/home/user/Android/Sdk/tools/emulator: ELF 64-bit LSB executable,
x86-64, version 1 (SYSV), dynamically linked, interpreter
/lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.15, stripped
As you can see emulator is 64bit binary, I run it 64bit OS,
also Tools->Android->Avd Manger show that Nexus_5X_API_23 has CPU/ABI = x86_64,
so what is "32-bit error" about?
Update
Looks like it need some permission, because of I can run emulator from root user. But still can not guess what exactly it need.
The problem was with the SHELL environment variable.
If I run emulator under root with SHELL=/bin/bash it all works fine, but if I run emulator from an ordinary user with SHELL=bash, it fails and shows the error message about 32 bit.
when I run ndk-build, it fails complaining from the following errors:
$ ndk-build
make: /…/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
Compile arm : jpeg <= jcapimin.c
make: /…/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: *** [obj/local/armeabi/objs/jpeg/jcapimin.o] Error 127
The problem is that although it says "command not found", "arm-linux-androideabi-gcc" exists in the above path. Even when I run "arm-linux-androideabi-gcc" directly from /…/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ it gives the same error of "command not found"
I also added ./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin to my PATH but still getting the same error. Even I tried different versions of ndk (7, 7b, 6b) still same error! seems to me the above gcc is meant for 32bit machines whereas my machine is "Linux 2.6.32-37-server x86_64". but I guess the ndk package should work for both 32 and 64bit. am I right? do I need to compile or build ndk before using it? I assume downloading and unpacking is all I have to do. right? how about sdk? I just downloaded and unpacked it at the same folder that I have my ndk. do I need to configure them to work with each other
I ran into the same problem. You are right, the problem is due to trying to run a 32-bit binary on a 64-bit kernel.
I solved it on Ubuntu 11.10 by installing the 32-bit compatibility libs:
sudo apt-get install ia32-libs