[Q] How to compile (big) C-Projects with Makefile for Android NDK - Android Software/Hacking General [Developers Only]

Hi,
i would like to compile a C-Library which is normally compiled with:
Code:
* ./configure with some parameters
* make
* make install
with the Android NDK for use in my Android Application. My Questions now is whats the easiest of getting a corresponding Android.mk file.
Thanks in advance.

Hi; I am not aware of any way to avoid doing this manually. Unless this library has lots of other dependencies, it shouldn't be too much work anyway (mainly populating LOCAL_SRC_FILES, as far as I know).
I'd be interesting to see if there's an automatic/semi-automatic way to help with this though, especially if dependencies are involved.

Have you done this before? Could you please describe how to do it? Whats the equivalent to the ./configure -someParameters ?

Give a try to our AGCC script from here. http://code.google.com/p/android-cruft/
I had a good luck cross-compiling many GNU project using this script. What you need to do is just download and unpack the script then run your configure script like this
CC=agcc LD=agcc ./configure
Make sure that agcc is in your path. After you run configure you can just make the project as usual. Note that as always when cross compiling the configure script could not as many tests as it does when compiling in the native environment, so you might need to supply extra options.
--- Vlad

Hi Vlad,
i tried it, but the scripts seems tu be using wrongs Paths. I'm Using NDK Version r5b, maybe thats the problem?
Here the first few lines of output from agcc:
GCC at /home/dirk/android-ndk-r5b/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin
DROID at /home/dirk/android-ndk-r5b/toolchains/arm-eabi-4.4.0
TOOLCHAIN at /home/dirk/android-ndk-r5b/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1
Click to expand...
Click to collapse
The Project I'm trying to compile is openpace.sourceforge.net. Maybe you have yourself a try.
Thanks so far.

Nevermind, i found a way using the new standalone toolchain included in NDK-r5 and newer.

So please tell us about your way!

Could you help me please?
Hello miracoli and others,
I'm trying to port a C-code to Android. I use it on linux terminals since the project started and it's perfect. The project it's called ser2net (see Links.txt attached). With this project you can create a server to your serial ports in your PC, and access them with putty,telnet,etc...
I compiled it with arm-none-linux-gnueabi-gcc but I have no success on run it:
Code:
# ser2net
ser2net: not found
You can download the compiled binary here (see Links.txt attached) and the configuration file here (see Links.txt attached). You must copy these 2 files to /etc to run it.
I compiled it and tested on MID 7 ARM9, for EKEN M009S WM8650 processor and Sony Xperia X10 Mini. I'm not an expert about Android but I've already ported lot of GNU projects to ARM9 and ARM11 architecture with no problem.
If it helps, I also created a dummy hello.c (only to say hello) and it built and run with no problem.
If somebody know how to have it done, post here. Or, if would like to contact me, please do it on skype: antonio.spadim.
Bye
Toni

Bump! No news?

Related

help porting a linux program to the android

hi all
i have created a custom rom for myself because i want to add a linux program: scanmem
i have copied the file in system/xbin
using this guide http://lukasz.szmit.eu/2009/12/making-your-own-rooted-android-rom.html on step6 for su command
the problem is that doesn't work ...
when i open a terminal in my desire and type :
su
scanmem
i receve this message:
scanmem: 1: syntax error: "(" unexpected
any help, suggestion ? scanmem is compiled for i386 32bit
kiokoman said:
any help, suggestion ? scanmem is compiled for i386 32bit
Click to expand...
Click to collapse
There's your problem.
Code:
[email protected]:/tmp$ file busybox
busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped
[email protected]:/tmp$
If you don't have the source, time and a cross-compiler, you have a problem It's also Little Endian from memory.
This is the busybox binary I tested in case you want to strip it down: http://benno.id.au/blog/2007/11/14/android-busybox
i found a lot of information with google
http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html
i have the source maybe i can compile for arm
kiokoman said:
i found a lot of information with google
http://www.kbrandt.com/2009/06/how-to-cross-compile-the-bash-shell-for-android-15.html
i have the source maybe i can compile for arm
Click to expand...
Click to collapse
Precisely. You should also check the dependencies (if any) and make sure you cross-compile those too.
jayshah said:
Precisely. You should also check the dependencies (if any) and make sure you cross-compile those too.
Click to expand...
Click to collapse
oh my god
depends on libc6 and readline6, i have to cross-compile half gnu/linux
out of my hand
Shame :/
Why did you need it anyway? Perhaps there is another way for what you want to achieve.
jayshah said:
Shame :/
Why did you need it anyway? Perhaps there is another way for what you want to achieve.
Click to expand...
Click to collapse
i think it was an easy program to port and with a frontend for android I would have used it as the first cheats system like cheat engine for pc
I made this. I compile scanmem fo my android phone (p500) from sourses.
He even gets up and running, but not quite.
Opt for a process (pid command)
It finds regions of memory. But during the search, crashes ". bus Error"
Maybe it's because of the specificity of an android, or due to the fact that I had to change all calls to readline lib, because otherwise the project will not compile.
I will continue to watch and understand ...
Done. Scanmem works fine on my phone.

[Q] Cross compiling C software for my android

Hi,
I've download the Android source with "repo", and it includes cross compiler toolchains for various architectures.
I want to build a package (for now, mtd-utils) for my android phone (a htc hero), but I'm having limited success understanding how to get this working. I was thinking there was something I could do, like change my $PATH and set up some other environment variables, that would use the tools from the toolchain instead of the system default ones, so that the binaries would be built for the phone instead of for my computer. But it certainly doesn't seem to be that easy...
I've reverted to attempting a "Hello world" program, but when I try to compile even that using the included toolchain tools, I run into trouble:
Code:
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -o hello hello.c
hello.c:1:19: error: stdio.h: No such file or directory
hello.c: In function 'main':
hello.c:5: warning: incompatible implicit declaration of built-in function 'printf'
so I tried a couple of other variants:
Code:
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -I $HOME/src/mydroid/bionic/libc/include -o hello hello.c
$ $HOME/src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -static -I $HOME/src/mydroid/ndk/build/platforms/android-8/arch-x86/usr/include/ -o hello hello.c
but they both give (different) errors about what other include files are missing when referenced from somewhere.
Is there some "easy" way to android-ify a source tree, so that I can build sources using the cross compiler toolchains? Or should I fetch a different cross compiler toolchain to use, like benno did in his document from 2007? He uses a codesourcery toolchain and builds with that instead (as referenced in other articles here on the subject).
Would much appreciate any shared tips or experiences on how to accomplish this.
The tool chain is fine the problem is non of the include/lib are set up correctly to find the needed version of the includes. Remember the default includes under linux depend on glibc and android only supplies bionic.
Have a look here for more info on setting up bionic:
http://android-dls.com/wiki/index.php?title=Compiling_for_Android
Though if you get the full source for glibc (or precompiled arm binaries) you could compile a dependant program staticly (I think that's what busybox does)
Building for older versions of Android
I was actually able to compile a program manually today, specifically one of the programs in the mtd-utils package. After lots of jumping back and forth, I have found out that the 64 bit version of Ubuntu is what I needed, and also sun-java-1.6, contrary to almost all information I found out there. Then I was able to build AOSP, and then I was able to get "agcc" working, the wrapper that sets environment variables automatically as needed.
So I compiled the app, but it didn't work on my Android. Trying to run it in an adb shell gave approximately this error (from memory):
/bin/sh: ./program: No such file or directory
though the program was there. I didn't use strace, but concluded that this is because of a missing shared library. I have a very recent version of AOSP, while the phone is running Android 2.0 or something like that, so that's a plausable reason why this is happening.
I tried to rebuild the program using "agcc -static ...", but that doesn't work because I don't have the static version of libc after building AOSP, so it just dies with a linker error complaining that it can't find -lc.
So now I need to figure out how to build for old Android version using my checked out version of AOSP, or I need to figure out how to check out an old version of AOSP using repo.
Any tips would be much appreciated.

[Tool]File(1) command for Android (ver 5.11)

After wandering around looking for an android build of the file command, I finally went ahead and compiled it myself.
The attached package contains the file binary (v5.11), the libmagic.so shared library, the associated magic files and the build specific files that I needed (over and above the source) to build it. The paths of the files are relative to '/'.
Refs:
source: file website (www_darwinsys_com/file/)
compiling: Native Vim on Android (gdr_geekhood_net/gdrwpl/vim-android.php)
Note: Add the location of libmagic.so to LD_LIBRARY_PATH to get rid of the "CANNOT LINK EXECUTABLE" error. (I use /data/local/lib)
Compiled a dynamically linked library and associated binary instead of the monolithic binary built earlier.
samveen said:
After wandering around looking for an android build of the file command, I finally went ahead and compiled it myself.
The attached package contains the file binary (v5.11), the libmagic.so shared library, the associated magic files and the build specific files that I needed (over and above the source) to build it. The paths of the files are relative to '/'.
Refs:
source: file website (www_darwinsys_com/file/)
compiling: Native Vim on Android (gdr_geekhood_net/gdrwpl/vim-android.php)
Note: Add the location of libmagic.so to LD_LIBRARY_PATH to get rid of the "CANNOT LINK EXECUTABLE" error. (I use /data/local/lib)
Click to expand...
Click to collapse
I followed your instructions and it works perfectly.
Code:
$ echo $LD_LIBRARY_PATH
/data/local/lib:/data/local/lib:/data/local/lib:/system/lib:/vendor/lib
$ file
Usage: file [-bchikLlNnprsvz0] [--apple] [--mime-encoding] [--mime-type]
[-e testname] [-F separator] [-f namefile] [-m magicfiles] file ...
file -C [-m magicfiles]
file [--help]
$ getprop | grep device
[ro.cm.device]: [jordan]
[ro.product.device]: [umts_jordan]
I have been looking for this for a while. Man!! This post needs some serious attention. Great work.
Sent from my MB525 usiIng XDA
@samveen Any chance you could compile it with libmagic statically linked again to make it portable? Thanks for your time.
osm0sis said:
@samveen Any chance you could compile it with libmagic statically linked again to make it portable? Thanks for your time.
Click to expand...
Click to collapse
@osm0sis Sure. I'll add in a statically linked binary, but it'll take a little time (2-3 days).
samveen said:
@osm0sis Sure. I'll add in a statically linked binary, but it'll take a little time (2-3 days).
Click to expand...
Click to collapse
I was just looking for this. Great tool.
Thanks for your work.
samveen said:
@osm0sis Sure. I'll add in a statically linked binary, but it'll take a little time (2-3 days).
Click to expand...
Click to collapse
Any luck? I think it only needs libmagic statically linked to be portable; the other NDK/Bionic stuff can probably stay dynamic to keep the filesize down. I see file 5.17 source is available now too if you wanted to update your builds to the latest.
osm0sis said:
Any luck? I think it only needs libmagic statically linked to be portable; the other NDK/Bionic stuff can probably stay dynamic to keep the filesize down. I see file 5.17 source is available now too if you wanted to update your builds to the latest.
Click to expand...
Click to collapse
If you want only the system file type, the workaround i use is this (eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE)
In a script just add a var like this
TYPE=$(eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE) and you will have the FS type in $TYPE.
Phone: Samsung Galaxy SII - GT-I9100
Kernel: Dorimanx kernel v10.43v99-mv3
1st ROM : SlimSaber 4.4.2 Maliv3 by fusionjack build of 20140320 (Online)
2nd ROM :
MODEM: UHMS1
MODS: Partition Fix, Hue Blue v4.4 by Kroz :good:
Computoncio said:
If you want only the system file type, the workaround i use is this (eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE)
In a script just add a var like this
TYPE=$(eval $(/sbin/blkid /dev/block/mmcblk0p11 | /sbin/awk ' { print $3 } '); /sbin/busybox echo $TYPE) and you will have the FS type in $TYPE.
Click to expand...
Click to collapse
Interesting but nope; I need file to determine a filetype. Compressed archives via a script, to be specific.
@osm0sis I got the code compiled (both with a dynamic libmagic.so, and libmagic compiled into file) but I need a little more time to compile the magic data (it requires running file on the target device to compile the magic data into a binary datafile). Once I have that figured out (either by compiling it or by creating a script to allow the users to do it themselves, I'll post it all in one go (need one more day).
samveen said:
@osm0sis I got the code compiled (both with a dynamic libmagic.so, and libmagic compiled into file) but I need a little more time to compile the magic data (it requires running file on the target device to compile the magic data into a binary datafile). Once I have that figured out (either by compiling it or by creating a script to allow the users to do it themselves, I'll post it all in one go (need one more day).
Click to expand...
Click to collapse
Awesome! Thanks so much. The magic file isn't terribly important since you can grab one a lot of places and specify it with the -m parameter; keeps the file size down too if you were thinking of including it in the binary somehow!
Alright. I just wanted to thank you again for your work but I managed to make a static native compile (~440kb) of file-5.17 using my N7 and a kbox build environment I set up. It's available in my ARM Android Image Kitchen linked in my sig. Cheers!
osm0sis said:
Alright. I just wanted to thank you again for your work but I managed to make a static native compile (~440kb) of file-5.17 using my N7 and a kbox build environment I set up. It's available in my ARM Android Image Kitchen linked in my sig. Cheers!
Click to expand...
Click to collapse
@osm0sis - Can you please share how did you static compile this? I have setup the Ubuntu 13.10 image on Android using Complete Linux Installer (with all the necessary build tools setup).
I am able to compile this, but it's linking the shared library "libmagic.la".
Need to pass --static to ./configure and have a cross compiler set up, for ARMv7.
ericlnu said:
Need to pass --static to ./configure and have a cross compiler set up, for ARMv7.
Click to expand...
Click to collapse
I don't think that's a valid option.
Code:
$ ./configure --static
configure: error: unrecognized option: `--static'
Try `./configure --help' for more information
amit.bagaria said:
I don't think that's a valid option.
Code:
$ ./configure --static
configure: error: unrecognized option: `--static'
Try `./configure --help' for more information
Click to expand...
Click to collapse
Nope, seems not ^_^. Sorry, it usually is with autoconf derived configure scripts.
amit.bagaria said:
@osm0sis - Can you please share how did you static compile this? I have setup the Ubuntu 13.10 image on Android using Complete Linux Installer (with all the necessary build tools setup).
I am able to compile this, but it's linking the shared library "libmagic.la".
Click to expand...
Click to collapse
Haven't tried it using a full Linux image on Android, just made it native compile in KBox2 on my N7'13 for awhile by editing in the gettext functions it was complaining about, and have since moved on to cross-compiling on my Windows 7 desktop in Cygwin using the NDK. There were still a few tricks to getting it to be a true static compile. It's all linked in my post here:
http://forum.xda-developers.com/showthread.php?p=54510825
My latest compile included in my AIK-mobile package is file 5.20. :good:
I don't suppose you could do a quick compile with the -fPIE flag? Trying to use this on 5.0 + and don't want to patch my linker.
Tried to compile it myself (it sort-of worked, file --version is operational) but when I try to actually use it for something my terminal borks out and switches to some weird font after about 20 warnings. (configure also seems to be using the -rpath flag apparently, linker complains about it) hmm
EDIT: I've got it working after some trial and error. If anyone requests I'll post it
EDIT 2: android 6.0's linker seems less forgiving than 5.0/5.1, need to compile without -rpath (so no just using ./configure) will keep posted
Can you please post the file binary you built with -pie ?

[UTILITY][ANDROID] XZ Utils port to Android - managing .xz archives now possible!

what is XZ Utils
XZ Utils is free general-purpose data compression software with high compression ratio. XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils.
The core of the XZ Utils compression code is based on LZMA SDK, but it has been modified quite a lot to be suitable for XZ Utils. The primary compression algorithm is currently LZMA2, which is used inside the .xz container format. With typical files, XZ Utils create 30 % smaller output than gzip and 15 % smaller output than bzip2.
Android port
XZ Utils makes managing .xz and .lzma (LZMA2) archives possible in Android APPs or tools .XZ Utils is easy to use and powerful . you may use it in your app or use it with terminal emulator ( push binary to /system/bin and set permissions to 755 )
This binaries support ALL Android based devices with Bionic C Library .
Download
You may download lastest binaries for Android-ARM here :
XZ Utils 5.0.5 – ARM – Android
Development
Main development of XZ Utils is running by Tukaani .
And git repo :
git clone http://git.tukaani.org/xz.git
Licence
The most interesting parts of XZ Utils (e.g. liblzma) are in the public domain. You can do whatever you want with the public domain parts.
Some parts of XZ Utils (e.g. build system and some utilities) are under different free software licenses such as GNU LGPLv2.1, GNU GPLv2, or GNU GPLv3.
Official XZ Utils and more information HERE
@alireza7991 Thanks for the work porting/compiling this for Android - exactly what I was looking for since (for some reason..) Busybox only supports xz/lzma decompression. :good:
The download link is dead now unfortunately - would you please rehost it somewhere?
Thank you in advance!
osm0sis said:
@alireza7991 Thanks for the work porting/compiling this for Android - exactly what I was looking for since (for some reason..) Busybox only supports xz/lzma decompression. :good:
The download link is dead now unfortunately - would you please rehost it somewhere?
Thank you in advance!
Click to expand...
Click to collapse
Sorry for download link,I'm gonna fix it ASAP.
UPDATE: fixed (link is available in OP)
UPDATE2: oh, It seems there 's a problem with new executable, I have to fix it. I just need some time.sorry.
Hey. I just wanted to thank you again for your work but I managed to make a static native compile (~765kb) of xz-5.0.5 using my N7 and a kbox build environment I set up. It's available in my ARM Android Image Kitchen linked in my sig. Cheers!
Since xz binary for android is missing I have compiled one static armv7 for all you, enjoy!
munjeni said:
Since xz binary for android is missing I have compiled one static armv7 for all you, enjoy!
Click to expand...
Click to collapse
@munjeni @alireza7991 Hi! Can you share the commands you used to get xz's ./configure to cross-compile to android? I'm trying to set it up on Cygwin using the NDK's standalone I made but I'm having troubles.
Edit: I think I figured out my main issue: the toolchain bin path needed to be added at the beginning of the PATH, not the end. :silly:
Now to generate configs for arm x86 and mips and figure out how switch between them and build.. (any tips here would be appreciated as well!) :good:
Edit 2: Another snag with the toolchain.. configure grabs the Windows path for ld instead of the Cygwin one, so we run into multiple targets due to the :'s. Starts happening around the libtool detection.
Edit 3: It appears I can force it to use the one in PATH with LD=arm-linux-androideabi-ld
Edit 4: Getting it to make a legit static compile is stumping me now, I've tried adding CFLAGS="-static -s" to the ./configure commandline but it doesn't work in L, meaning it's not actually static (maybe due to zlib or something?).
munjeni said:
Since xz binary for android is missing I have compiled one static armv7 for all you, enjoy!
Click to expand...
Click to collapse
@munjeni Can you please explain how you statically compiled it? Configuring with --disable-shared --enable-static doesn't seem to work. Neither does inserting the -static flag various places into the built Makefile.
Try with LDFLAGS
munjeni said:
Hope this help https://github.com/munjeni/android_real_web_server/blob/master/MUNJENI_COMPILATION.sh
Click to expand...
Click to collapse
Thanks for replying! Cool stuff, but I don't see xz in there, and am struggling to see any lessons I could apply offhand from it.
munjeni said:
Try with LDFLAGS
Click to expand...
Click to collapse
Tried adding it with -Wl,--gc-sections,-static but that results in "checking whether the C compiler works... no", trying it separate now.
Here's my setup, under config (before): http://forum.xda-developers.com/showpost.php?p=54510825&postcount=277
Here's what I'm trying now (simplified):
Code:
savedpath="$PATH";
ldflags="-Wl,--gc-sections -static";
cflags="-g -O3 -ffunction-sections -s";
export PATH="~/x-tools/arm-linux-androideabi/bin:$PATH";
cd ~/xz*;
./configure --host=arm-linux-androideabi --disable-shared --enable-static LD=arm-linux-androideabi-ld LDFLAGS="$ldflags" CFLAGS="$cflags" CPPFLAGS="$cflags" CCASFLAGS="$cflags" --disable-xzdec --disable-lzmadec --disable-lzmainfo --disable-lzma-links --disable-scripts;
export PATH="$savedpath";
I feel like I tried it in LDFLAGS before, but fingers-crossed. :fingers-crossed:
Edit: @munjeni Still no luck, unfortunately. It statically links liblzma but not libc or libdl:
Code:
[email protected] ~
$ ndk-depends() { ~/x-tools/$1/bin/$1-readelf -d $2 | grep NEEDED; }
[email protected] ~
$ ndk-depends arm-linux-androideabi xz
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libdl.so]
How did you execute configure, and/or alter the resulting Makefile to get a true static compile?
I had problems with xz and sorry I forgot how I solved them, probably (I think) I have linked with static libc! Or probably (maybe) some of the depended libs was not static which caused me failed xz static compilation so maybe I have compiled staticaly other dependencies and linked with xz! Bionic is realy an sh*t Hope this help.
munjeni said:
I had problems with xz and sorry I forgot how I solved them, probably (I think) I have linked with static libc! Or probably (maybe) some of the depended libs was not static which caused me failed xz static compilation so maybe I have compiled staticaly other dependencies and linked with xz! Bionic is realy an sh*t Hope this help.
Click to expand...
Click to collapse
Tried adding --with-sysroot= to the ./configure command-line and -lc -ldl to the CFLAGS (and LDFLAGS) to try and get it to find/link them all but still no luck.
@munjeni If you ever do remember/recreate what you did to get xz to compile statically, please share it here/somewhere on xda and mention me. It's actually applicable to all autotools (./configure) built sources, so would definitely help a lot of people with a lot projects. Especially with Android L coming along, requiring everything to be static or PIE (with static preferred for backwards-compatibility). :good:
osm0sis said:
Tried adding --with-sysroot= to the ./configure command-line and -lc -ldl to the CFLAGS (and LDFLAGS) to try and get it to find/link them all but still no luck.
@munjeni If you ever do remember/recreate what you did to get xz to compile statically, please share it here/somewhere on xda and mention me. It's actually applicable to all autotools (./configure) built sources, so would definitely help a lot of people with a lot projects. Especially with Android L coming along, requiring everything to be static or PIE (with static preferred for backwards-compatibility). :good:
Click to expand...
Click to collapse
Put your libc.a and libdl.a to the new place. for example put them to new folder caled /tmp/compilationfolder, than try flags:
LDFLAGS="-L/tmp/compilationfolder" LIBS="-lc -ldl"
to make sure it get linked with static libs! If compilation fail to find other libs than locate missing libs and move them to these folder and try again until...
EDIT:
If I remember corectly I think now I have removed shared libs in sysfolder of the toolchain just for compiling xz!
@osm0sis : What toolchain are you using? I really hope you're NOT trying to use the MentorGraphics/CodeBench/CodeSourcery garbage. Only trouble with their stuff. Also, when using Cygwin for these kind of things your putting yourself in deep water or trouble from the start. Use a VirtualBox VM. The list of problems when trying to compile any *nix stuff on windows is nearly endless.
Check this:
"Cross-compiling: Building_the_Kernel_using_Cygwin"
NDK all the way. Yeah I know I should fire up the Ubuntu VM, but I was having such fun (successfully) getting it all to work in Cygwin so far until this roadblock in making xz static.
Either way, I think munjeni was using Linux and ran into the same problems until he started messing with the toolchain sysroot, so it's not just Cygwin.
munjeni said:
Put your libc.a and libdl.a to the new place. for example put them to new folder caled /tmp/compilationfolder, than try flags:
LDFLAGS="-L/tmp/compilationfolder" LIBS="-lc -ldl"
to make sure it get linked with static libs! If compilation fail to find other libs than locate missing libs and move them to these folder and try again until...
EDIT:
If I remember corectly I think now I have removed shared libs in sysfolder of the toolchain just for compiling xz!
Click to expand...
Click to collapse
I believe you are on the right track with this idea but my concern with it now is that there are multiple definitions upon compiling against liblzma.a and a few others. Causes errors. I then took a shot with just libc.so libdl.so and this went fine without any errors but they still appeared as dynamic when checking with: objdump -p ./xz
@osm0sis, guess what I have
Code:
xz-5.0.5$ cd ./src/xz
xz$ objdump -p ./xz
./xz: file format elf32-littlearm
Program Header:
0x70000001 off 0x00051d58 vaddr 0x00059d58 paddr 0x00059d58 align 2**2
filesz 0x000009e8 memsz 0x000009e8 flags r--
LOAD off 0x00000000 vaddr 0x00008000 paddr 0x00008000 align 2**15
filesz 0x00052740 memsz 0x00052740 flags r-x
LOAD off 0x00058264 vaddr 0x00060264 paddr 0x00060264 align 2**15
filesz 0x00000fa0 memsz 0x0000dae4 flags rw-
NOTE off 0x00051c44 vaddr 0x00059c44 paddr 0x00059c44 align 2**2
filesz 0x00000018 memsz 0x00000018 flags r--
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**2
filesz 0x00000000 memsz 0x00000000 flags rw-
RELRO off 0x00058264 vaddr 0x00060264 paddr 0x00060264 align 2**0
filesz 0x00000d9c memsz 0x00000d9c flags r--
private flags = 5000002: [Version5 EABI] [has entry point]
xz$
---------- Post added at 01:17 AM ---------- Previous post was at 01:03 AM ----------
@osm0sis, if you wish to compile xz statically then the following example will do the trick. It's so SIMPLE I about fell out of my seat. Pay attention to what I have in bold:
./configure --build=arm --host=arm-linux-androideabi LDFLAGS="-static"
Then, when you go to run, make, just do the following:
make LDFLAGS=-all-static
Update:
After some tests with @osm0sis we learned that using configure will ultimately overwrite the original flags ordained by the source. Running the configure normally then applying your flags using "+=" will insure the ordained flags do not get overwritten as well as including your own additional flags. This will ultimately be up to the user what they want to do and their ultimate goal at the end of the day.
--- Happy Hunting!!
You freaking genius! No modification of the NDK toolchain required!?
osm0sis said:
You freaking genius! No modification of the NDK toolchain required!?
Click to expand...
Click to collapse
Nope
Modding.MyMind said:
Nope
Click to expand...
Click to collapse
Can't wait to try that out in the morning. You've just fixed static NDK compiling on anything using Autotools, bro!
osm0sis said:
Can't wait to try that out in the morning. You've just fixed static NDK compiling on anything using Autotools, bro!
Click to expand...
Click to collapse
Let me know how it works out for you. I tried this method on my phone too and it worked like a champ

Kernel compilation/booting troubleshooting for beginners

I've only recently after lot of struggle compiled my first kernel. While the information is still fresh in my mind, I want to share all the problems I encountered and what to do if you are in the same situation.
This guide is mainly for Linux users since that is what I am familiar with.
I've used this amazing guide to learn the basics. If you haven't yet, read it first.
Errors from scripts/gcc-wrapper.py
Open the file and change the first line from
Code:
#! /usr/bin/env python
to
Code:
#! /usr/bin/env python2
Kernel won't compile
* Did you forget to set and export the variables ARCH and CROSS_COMPILE?
* Do you have the right .config file present?
Try extracting the .config file from the original boot kernel and use it instead
* Are you sure you are in the correct branch?
Run git branch inside kernel's source code to verify that
* Are you using a very recent or very old version of the compiler? Some old kernels for example would only compile with gcc-4 but not gcc-7 or 8. Most kernels - at the time of writing - won't compile with gcc-8
Kernel compiles fine but won't boot
* Are you using wrong kernel configuration (.config) ?
* Try different compiler or different compiler version.
I've tried to compile my current with Android's prebuild gcc 4 compiler and it wouldn't boot, switched to gcc 7 and it booted perfectly fine.
Kernel starts but system crashes somewhere during boot
You can enable adb during boot so that you can see what causes the error.
Find this file in your extracted boot image ramdisk/default.prop
Set or update the following values
Code:
ro.adb.secure=0
ro.secure=0
persist.sys.usb.config=adb
Then you can do adb shell logcat or adb shell dmesg to see what is going on
My phone won't boot after flashing my new kernel, how do I boot to recovery?
First of all, you shouldn't have! You should test your new kernel without flashing it using fastboot.
Simply reboot to bootloader then run the command
Code:
fastboot boot /path/to/my/new-image
So what can I do now? Try to reach bootloader screen. the method differs from device to device but it involve pushing certain physical phone buttons while turning on the phone.
Once you are in the bootloader screen, you can do adb fastboot /path/to/twrp-recovery.img or even path to original boot image if you kept a backup.
ramast_ said:
I've only recently after lot of struggle compiled my first kernel. While the information is still fresh in my mind, I want to share all the problems I encountered and what to do if you are in the same situation.
This guide is mainly for Linux users since that is what I am familiar with.
I've used this amazing guide to learn the basics. If you haven't yet, read it first.
Errors from scripts/gcc-wrapper.py
Open the file and change the first line from
Code:
#! /usr/bin/env python
to
Code:
#! /usr/bin/env python2
Kernel won't compile
* Did you forget to set and export the variables ARCH and CROSS_COMPILE?
* Do you have the right .config file present?
Try extracting the .config file from the original boot kernel and use it instead
* Are you sure you are in the correct branch?
Run git branch inside kernel's source code to verify that
* Are you using a very recent or very old version of the compiler? Some old kernels for example would only compile with gcc-4 but not gcc-7 or 8. Most kernels - at the time of writing - won't compile with gcc-8
Kernel compiles fine but won't boot
* Are you using wrong kernel configuration (.config) ?
* Try different compiler or different compiler version.
I've tried to compile my current with Android's prebuild gcc 4 compiler and it wouldn't boot, switched to gcc 7 and it booted perfectly fine.
Kernel starts but system crashes somewhere during boot
You can enable adb during boot so that you can see what causes the error.
Find this file in your extracted boot image ramdisk/default.prop
Set or update the following values
Code:
ro.adb.secure=0
ro.secure=0
persist.sys.usb.config=adb
Then you can do adb shell logcat or adb shell dmesg to see what is going on
My phone won't boot after flashing my new kernel, how do I boot to recovery?
First of all, you shouldn't have! You should test your new kernel without flashing it using fastboot.
Simply reboot to bootloader then run the command
Code:
fastboot boot /path/to/my/new-image
So what can I do now? Try to reach bootloader screen. the method differs from device to device but it involve pushing certain physical phone buttons while turning on the phone.
Once you are in the bootloader screen, you can do adb fastboot /path/to/twrp-recovery.img or even path to original boot image if you kept a backup.
Click to expand...
Click to collapse
good job!
Do you have any general tutorials on kernel optimization?
wangyiling said:
good job!
Do you have any general tutorials on kernel optimization?
Click to expand...
Click to collapse
I am afraid not, sorry. I am just a beginner
@ramast_
The information you provided has solved pretty much all of the problems I was having. We need more content like this. Everything I find about kernel building explains things like you're a Linux expert, where as your post is much more layman friendly. I can't thank you enough for this.
Quick question; which version of Linux do you use?
You are very welcome, happy someone found it useful.
By Linux version I suppose you mean Linux distro (distribution).
I use Gentoo which is certainly not for beginners.
I'd suggest Ubuntu for beginners. Not because it's the best but because it has a very big community and you are more likely to find help when facing any problem.
This article explain how to cross compile arm code (how to compile code so that it can run on an arm device). Should get you started.
Best of luck
Spaceminer said:
@ramast_ I can't thank you enough for this.
Quick question; which version of Linux do you use?
Click to expand...
Click to collapse
ramast_ said:
You are very welcome, happy someone found it useful.
By Linux version I suppose you mean Linux distro (distribution).
I use Gentoo which is certainly not for beginners.
I'd suggest Ubuntu for beginners. Not because it's the best but because it has a very big community and you are more likely to find help when facing any problem.
This article explain how to cross compile arm code (how to compile code so that it can run on an arm device). Should get you started.
Best of luck
Click to expand...
Click to collapse
Thanks again. Distro is what I meant. I was thinking I should use Ubuntu, but I wanted to see what you had to say about it.

Categories

Resources