I have to C program which is compiled using gcc in ubuntu. I want to run that executable in android terminal. When i run it is showing either "file or directory is not found" or "not executable:ELF32". I want to run the code in android terminal. Is there any way or flags in gcc or using any other compiler so that i can run my code in the android terminal.?
1 Answers
Android does not use the same system libraries as Ubuntu, so they will not be found.
There are two solutions:
Copy the libraries you need.
If you can place them in the same filesystem locations they have in Ubuntu then great, otherwise you'll need to run the ld-linux.so manually and tell it where to find the libraries. Or, you could relink the program such that it expects to find the dynamic linker and libraries in a non-standard place. You might also use a chroot, but that requires root, and you'd need to find a chroot binary that works.
Use a static link.
This usually just means passing
-static
to GCC. You get a much larger binary that should be entirely self-contained, with no dependencies. It requires that static versions of all your libraries are available on your build system. Also, some features (such as DNS lookup) always expect a shared library, so they won't work this way.
Even then, you should expect some Linux features to not work. Basically, anything that requires hardware features or configuration files in /etc are going to need a lot of effort. There are various projects that have done this already (search "linux chroot android").
I'm not sure what the "not executable:ELF32" message means, but you should check whether you're building 32 or 64-bit executables, and which the Android binaries are using (file <whatever>
should tell you).

- 24,923
- 4
- 54
- 75
-
I compiled with -static, but its showing the second error ie.. "not executable:ELF32". There are some android specific flags in gcc like -mandroid which will compile for android platform. But its showing an error like "/usr/bin/ld: cannot find crtbegin_static.o: No such file or directory collect2: error: ld returned 1 exit status".. If you know anything about this, please help. – Anand B S Jan 20 '17 at 13:44
-
Are there any clues in the logs? (Run `logcat`.) The thought occurs that Android uses SELinux and there might be a security policy in your way. – ams Jan 20 '17 at 13:48