I would like to use a shared library, that is compiled for arm64, on Android. I have my .so file inside a aarch64-linux-gnu folder, but for other libraries I have instead a aarch64-linux-android folder.
Please can these libraries compiled for aarch64-linux-gnu run on an arm64 Android device? What do these names stand for precisely? I know that aarch64 refers to the arm64 processor architecture but I don't know how the operating system is related here.
Thank you!
Android and ARM my have some libraries that are the same. Basically the SO file has to be able to find all the libraries it was linked against to run, and the versions need to match up so nothing breaks. This is risky, and it is generally safest to compile the entire program on your target machine. You can see if everything can be located/what is missing using:
ldd /path/to/file.so
this will give you a list of libraries and where the file thinks they are - or ??? if it can't find it. You need to double check and see if the results of this look OK.
Even if all dependencies are found, mismatch in versions or architecture will cause the program to break at run-time. You need to extensively test the use of the externally linked library and even then you may miss some cases that break your program. For this reason I would try and get the source code if possible, and re-compile everything on the target machine.
Related
I need to compile libmysqlclient and librtlstr for Android (in fact I could find rtlsdr, but since I need mysqlclient the issue is still there).
I followed several guides but most of them present the instruction written here http://mortoray.com/2012/08/21/android-ndk-cross-compile-setup-libpng-and-freetype/
Anyway, the package I download did not contain any configure file so I don't know how to continue.
Because the purpose of this file should only be the creation of the makefile, maybe there is a way solve this.
So my questions are:
1) Is this the right approach? Are there others easier?
2) Does a general configure file exist so that I can download and use it?
3)If not, how does the makefile has to be written? This way I should be able to overcome the abscence of configure file
I need those libraries to port a c code (which needs them) to android building an executable that I'll run on my phone (so I already have the standalone toolchain from the NDK), if it helps
1) This is right approach (may be a little bit simplified, I'm using more steps to build) for libraries, which use automake. Much easier, if library uses Cmake (must contain CMakeLists.txt), because you need only NDK. Example: cmake -DANDROID_NDK=path/to/ndk -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-21 ..
2) No, also you need provide additional files (for example, Makefile.in)
3) This libraries have to use one of tools such CMake, automake etc, just Makefile or project for some IDE. So, try to find out, what of this use your libraries
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.
I'm trying to cross-compile the qhull library for Android, on a Linux x86-64 host. I'm fairly new to CMake, but rather experienced with other buildsystem tools.
I've setup a toolchain file, according to all the recommendations I've found, and it has worked for several other packages. Yet, no matter what I try, nothing seems to augment the linker path for one or more of qhull's executable programs. The problem is that it can't find Android NDK's libsup++.a, which is an implicit dependency of its compiler (GCC). If I take the generated link command and manually add -Lpath_to_libsup++.a, then the link succeeds.
In my toolchain file, among the things I've tried are:
CMAKE_FIND_ROOT_PATH
link_directories()
CMAKE_EXE_LINKER_FLAGS
I don't see anything unusual about its CMakeLists.txt, at least with respect to the first point of failure (user_eg3).
I'd prefer not to patch the library, if possible. I know many others are using this on Android (it's a dependency of point cloud library), so I assume I'm probably missing a step.
BTW, I'm using CMake v3.4.3, Android NDK r10e, and qhull v7.2.0.
I found a workaround.
In this post, Florian mentioned that CMake internally sets CMAKE_EXE_LINKER_FLAGS_INIT to $ENV{LDFLAGS}. I've found that if I set the environment variable LDFLAGS=-Lpath_to_libsup++.a, it gets passed through to the link command, which now succeeds.
I'd still like to know the proper CMake solution to this problem. Or, if the problem lies with qhull, then maybe someone can peek at its CMakeLists.txt (linked above) and point out what it's doing wrong.
I have code I compiled already, and wonder if I can use the resulting executable, which is in elf format as a library in an APK and how please.
#Gabe Sechan; thanks. I did build a JNI project. I am having some issues importing the code from my other project into JNI. I wonder if you can suggest the best way to import it. I can post my Android.mk file if you like. Basically, it seems that project finds the first file, and an associated header file. That file, in turn uses variables, which are defined in another file. But there is no include statement.
You know? I figured if I can use a JAR file as a library, perhaps I could use an executable also. I need to learn more.
# Chris Straton - Thanks. I did edit my post with a comment to address the toolchain issue. But then, I modified it. Regardless, What I stated was if I use the toolchain that is recommended by my target platform, then I should be able to run it on my phone right?
Further; I re-read your comment about ABI and libc compatibility. The two devices are tegra t132 and Samsung S-N900P. So libc should not be an issue since both devices run Android; right? As far as I know both have an arm chip. Is there anything else I need to look into?
Elf is an executable, not a library. What you want to do is get a .so file and link to it via JNI.
You could possibly run it as a command line program and interact with it via its stdin and stdout, but that would be clunky when you can just use it as an actual library.
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.