1

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

  • 1
    pthread (or at least a subset of it) is already included in bionic (Android's libc implementation). Anyway, it's unclear exactly what you've downloaded. You can't just take libraries built for some generic arm64 Linux distro. They need to have been built using the Android NDK. – Michael Feb 01 '18 at 16:31
  • Yes,I suspected that,but mine was an attempt to see if the problem was the pthread included in bionic: if I use the bionic one I got the compiling error saying it cannot find libpthread.so.0 This is the one I would like to solve; the other error 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 Anyway I'll edit my question to be clearer – Andrea Rufini Feb 02 '18 at 08:34

1 Answers1

0

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.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • But I am using the NDK toolchain: in fact I build my toolchain as expressed here https://developer.android.com/ndk/guides/standalone_toolchain.html#itc specifying the architecture (arm64). This way for example I can compile a simple "hello word" and make it run on Android, so the compiler itself should be ok. The problem is compiling the c code I have, not written by me, which compile well on linux or windows and needs libpthread (-lpthread in LIBS in makefile) among other libraries. I don't knowhow to properly use libpthread in the toolchain, cause the default one seems to be insufficient – Andrea Rufini Feb 02 '18 at 08:27
  • That's exactly my point: you cannot mix the two approaches. As for **-lpthread**, you can remove this from your link command, or if this is too complicated, you can provide an empty static library **libpthread.a**. As for **librtlsdr** and **libmysqlclient**, you need compatible arm64 builds of these libraries. Maybe, it would be easier to build them yourself. – Alex Cohn Feb 02 '18 at 14:57
  • So the thing is, I should remove -lpthread and so on, and provide static libraries for arm 64 which are compatible for Android. But how am I suppose to build myself those library? (cause I think they don't exist) Do I have to fiind source code and compiling it with my toolchain? – Andrea Rufini Feb 02 '18 at 15:06
  • There seem to be some repos on GitHub for Android variation of librtlsdr. I don't have personal experience with them. As for mysql, it looks like you will need to port a Linux library, which may not be easy. – Alex Cohn Feb 02 '18 at 15:25
  • Yes, I'm positive for librtlsdr but I think I woun't be able to find the other two. It seems I'll havo to look for a way to build myself – Andrea Rufini Feb 02 '18 at 16:37
  • No, I don't think you should build libpthread. As @Michael explained yesterday, Android has all pthread functionality built into its libc. – Alex Cohn Feb 02 '18 at 16:57
  • 1
    Ok, removing -lpthread probabily solved that, because it should pick the android one. Obviously this way now libmysqlclient is still searching for libc.so, the problem is almost the same. I'm trying to figure out how to properly compile the .so for Android but is not as easy as I tought – Andrea Rufini Feb 06 '18 at 10:26
  • Please keep me updated when you find how to build libmysqlclient for Android. An easy alternative could be to switch to sqlite. – Alex Cohn Feb 06 '18 at 15:01