Want to build & install Glibc in Android (bionic) - android

But i am getting error..
My configure option was
../configure CFLAGS="-march=native -Wp,-D_FORTIFY_SOURCE=2 -O2 -pipe" --prefix=$PREFIX --libdir=$PREFIX/lib --libexecdir=$PREFIX/lib --with-headers=$PREFIX/include --enable-bind-now --enable-cet --enable-kernel=5.10 --enable-stack-protector=strong --disable-profile --disable-crypt --disable-werror --enable-systemtap --target=aarch64-linux-android --host=aarch64-linux-android
I am trying to compile glibc for Android (bionic) base Termux ..
Compiling with gcc but depending on bionic
aarch64-linux-android
My host processor aarch64
My target processor aarch64
My host platform Android 12 (termux)
My target platform Android 12 (termux)
I want to build & install in termux..
And termux not depending on aarch64-linux-gnu..
Termux depends on aarch64-linux-android
mey be it is not possible.. but i am trying to do it for experimental purpose..
I have all dependency package installed like gcc, clang, python etc..
Somewhere i found glibc for termux..
But it is not depending on aarch64-linux-android
I know developer can do anything..
I don't know any computer language so i want help..
My error log
In file included from <command-line>:
syslog.c: In function '__vsyslog_internal':
syslog.c:94:30: error: inlining failed in call to 'always_inline' 'syslog': function not inlinable
Somehow i removed a single line 134 from syslog.c solved this issue..
But after last position i received too many undefined reference to error..
https://pastebin.com/U8NcNf97
Don't know how do I solve..
Thank you..

I don't want to offend you, but you are essentially wasting your time trying to compile glibc with bionic compilers. To compile glibc, you need glibc (i.e. glibc-based compiler and dependencies) - this is the most correct approach. It may be possible to compile glibc with bionic, but the setup process will be terribly complicated and time consuming (plus, it will be a completely different library, in effect).
Also, I want to say that you configured PREFIX incorrectly in configure. It's better to separate glibc and all its bases from the bionic-based termux system, then you risk breaking termux. In addition to properly configuring configure, one should remove running unsupported system calls in glibc source files, this is important as such system calls can cause a Bad system call error when starting any glibc-based program.
For understanding, I have experience compiling glibc for termux - https://github.com/Maxython/glibc-for-termux.

Related

Native C Android - Issue in building executable with libptrhead

I'm trying to build an executable from a c file (not written by me) so that I can use it on my phone.
I'm using a toolchain directly from the Android NDK (that use Clang) built for arm64.
The c file needs, as expressed in the makefile, libpthread librtlsdr libmysqlclient, so I downloaded the arm64 versions of these libraries in my toolchain sysroot directory. First question: is this the right way of doing this?
Anyway, after doing this and executing make, it fails saying that it cannot find libpthread.so.0 and libpthread_nonshared.a.
To solve this I copy in the sysroot folder the file it wants from the libc6 arm 64 package (that are not only the two written above, but many others needed in cascade): this way the "make" seems to work fine but once I push it in my device, with the libraries it needs, and run it, I got a runtime error saying:
cannot find verneed/verdef for version index=32770 referenced by symbol "_res" at "/data/local/tmp/TEMP/libc6.so.6"
In this case the problem should be libc6, but I can't figure how to solve this.
This one is related to the libpthread I've downloaded, so the libc6 package, which is probably not suited for Android.
So the real problem is: is there a way to get rid of the first error I mentioned using just the pthread included in Android?
What I hope is that I'm just missing something or using in the wrong way.
Thanks
No, this is not how you are expected to build an executable for Android. You can either use the NDK toolchain, or an alternative toolchain, as described here: Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc.

How to build from src to binary for Android

I want to use some function calls(commands) designed for linux. I can use them by enter the key words in adb(Android CML).
Here I found some works some people did.
wget (because it isn't included in most Android device )
Iperf
But after reading their methods or suggestions, I can only understand that I need to use Android NDK and write the correct makefile. I have no idea about building others source code (most of them are C/C++) for linux(only need to use 'make' command mentioned in their README file). The official NDK document is for Java environment to call C lib mainly.
Are there some HOWTO, courses or suggestions for this. Thanks!
I have compiled single cpp file program. I try to compile a alternative version iperf
https://github.com/tierney/iperf
It seems to be relative to lib ,some header files, and multiple c files. I failed to compile by enter all c files normally. Is there anything I missed?
yeah you need the NDK, it offers an C/C++ compiler for Android.
In general the steps are all the same:
Setting up the NDK (I wrote a small how-to, but it's for Arch-Linux and the fish-shell, Windows how-to)
Adjusting your make file (instead of gcc compiler use Android NDK compiler, and so on)
Remember that Android uses Bionic C library, so only use functions supported by it
Run make, push the program to your device and make it executable
Of course, this is just an overview how it is done. You should try it and then ask specific questions if you run into troubles.
NDK is mostly intended to extend the Java apps, but you can download NDK and create a standalone toolchain from it (see http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html). Now you have a cross-compilation environment which is very similar to standard Linux dev environment.
In addition, for small executables and for testing only, you can also cross-compile and link statically to the libc. This way you don't have to worry about Bionic which could be a loss of time.

Header files for c code compiled by arm-gcc compiler

I used string.h header file in a c code that is to be compiled using arm-gcc compiler and the executable generated is to be executed on an android device.
When I pushed my executable on to the device and executed it, it presented me with linkage error.
How can I use functions from string.h on such a device?
Are these header files hardware specific?
The ARM EABI states that the header files for the ANSI C-library should be provided by the compiler independent from where the library comes. If you are cross-compiling you do however have to make sure you use the string.h coming with the compiler and not from the native system. What linkage error did you get?
It sounds like strstr is missing in the libc, which sounds weird and I don't have an explanation for it. If you have access to the library on the device, then I would check with for example objdump -t if it defines strstr.
How can I use functions from string.h on such a device?
It's worked for me in the past.
Are these header files hardware specific?
With the NDK tools, they are architecture and platform (e.g., Android 8, Android 14, et al.) specific.
Unless there's a serious bug in the NDK (which seems unlikely), I think you might want to check your build again.

Android cross compiling C with no configure file

I've recently started to cross compile a couple of C applications for Android. I've successfully done this for image conversion software using the following pseudo-instructions:
Build the Android toolchain
Compile Automake and Autoconf
Set the CC and CXX environment variables
Build the source package (delete configure, configure.sub, configure.guess, run autoconf configure.ac > configure, run configure with CFLAGS using arm-linux-androideabi, make and make install)
I am now trying to do this for an OCR library written in C. The problem that I am running into is that the library has no configure, configure.guess, or configure.sub. It only has a makefile.
I am not too familiar with C, but is there any different process that I should be following in this situation?
The ./configure step:
CFLAGS=’-march=armv7-a –mfloat-abi=softfp’ ./configure –prefix=/home/user/Downloads/install/usr/local –host=arm-eabi –enable-shared=no –with-modules --enable-delegate-build
is there any different process that I should be following in this situation?
Not really. I mean, if you plan to work with the Android Standalone Toolchain, then all you need to do is:
create the toolchain with the ad hoc target, e.g --platform=android-9
add the toolchain directory to the PATH (for convenience)
export the sysroot path, e.g. export SYSROOT=/tmp/my-android-toolchain/sysroot (for convenience)
set your C compiler (export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT") and archiver, if you target a static library (export AR=arm-linux-androideabi-ar)
Then it all depends about how your Makefile has been written, i.e what are the targets? influential environment variables? etc. But in practice, if the default target fits your need, all you need to do is to run make while overriding the C flags to set the target architecture (ARMv7 here):
make CFLAGS="-march=armv7-a"
That's it. Repeat with other archs (armeabi, x86, etc) if needed.
You can see a complete example for jsmn - a lightweight JSON parse written in C, here: http://git.io/ndk-jsmn.
I've also a set of slides that cover this topic that you may find useful.
According to this article: What does a typical ./configure do in Linux?
configure only checks for system dependencies (if they are missing it exits), checks the type of system you are on, adn then creates a makefile. since you already have a makefile, you should already be able to execute make install.

Setting up an Android build environment for JNI applications

I've got a hold of a proprietary JNI application which I need to build for a MIPS device. I've read "Initializing a Build Environment", parts of the NDK docs, some Google Groups threads and numerous StackOverflow questions, but I'm still short of my answer.
So far, I've checked out the Android source using Google's repo script and have it under ~/AndroidSource. I've also separately downloaded the SDK under ~/AndroidSDK and the NDK under ~/AndroidNDK. The code I'm trying to build is in a separate location. The SDK and NDK binaries are in my path. For building, I tried to use two different versions of the NDK as well as the one under the Android source tree, and experienced different sets of problems. My current setup uses NDK r8b, downloaded separately from the Android source.
The application has its Android.mk and jni/Android.mk. However, several directives in the latter point to paths such as
frameworks/base/include
system/core/include
with no prefixes. I thought these were meant to point to the respective directories in the Android source, so I symlinked them to the current directory. After some more symlinking and makefile and source hacking, I got the application to compile, but am currently stuck on the linking phase with lots of references to missing method bodies. During the whole time I knew I was doing something wrong.
I'm on a Linux x86_64 host, if it is of any concern.
So my question is:
What is the proper method to set up a build environment for JNI applications? What environment variables, symlinks and/or path expansions should I set up? Do I need to call any scripts once or before each ndk-build invocation?
Also, I'd be happy if you corrected me on any concepts or terminology I've gotten wrong.
Your approach wiyh symlinking the AOSP tree for system headers is correct. What you need now are the system libraries compiled for MIPS. The easiest way to get them is to adb pull them from a target device (or emulator image). But you can also build these libraries yourself, as part of the AOSP build (see build instructions for the source tree you downloaded).
If you still have any problems remaining, run your ndk-build with parameter V=1 and publish the link command and its results.
I use the following in my build (YMMV).
Explicitly invoke arm-linux-androideabi-gcc as your compiler or linker (should be in PATH).
NDK_PLATFORM=/path/to/android-ndk-r*/platforms/android-14
Pass -I"$(NDK_PLATFORM)/arch-arm/usr/include" to the compiler
Pass -nostdlib -L"$(NDK_PLATFORM)/arch-arm/usr/lib/" -lgcc -lc -lm to the linker

Categories

Resources