Ajay
Ajay

Reputation: 370

Unable to run x86 executable compiled by NDK

Here are the Android.mk and Application.mk files of my project with a JNI component:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

include $(OPENCV_ANDROID_ROOT)/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := exeFileName
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := file1.cpp file2.cpp file3.cpp
LOCAL_LDLIBS    += -llog -landroid -lEGL -lGLESv1_CM

include $(BUILD_EXECUTABLE)

Application.mk

  APP_STL := gnustl_static
  APP_CPPFLAGS := -frtti -fexceptions
  APP_ABI := all
  APP_MODULES := exeFileName

ndk-build successfully builds execuable for all architectures. But when I try to run the executable in ./libs/x86/, the executable is not recognized valid on my 64bit linux desktop. The exact error is "bash: ./libs/x86/exeFileName: No such file or directory" I examined the executable for missing links to the library using ldd here is the output:

linux-gate.so.1 =>  (0xf77b1000)
liblog.so => not found
libdl.so => not found
libz.so => not found
libandroid.so => not found
libEGL.so => not found
libGLESv1_CM.so => not found
libc.so => not found
libm.so => not found
libstdc++.so => not found

However, if I push the executable from ./libs/armeabi/ on the phone and execute it from shell on the device, it works.

Could you help me figure out the reason why I am unable to run the x86 executable?

Upvotes: 2

Views: 1384

Answers (2)

Digit
Digit

Reputation: 2113

You simply cannot run Android x86 executables on a regular Linux desktop. Only on an Android/x86 based system (or virtual device, when using the emulator).

Upvotes: 0

mstorsjo
mstorsjo

Reputation: 13317

The executable that is built for Android requires dynamic libraries that aren't available on your computer, as you found out with ldd. Additionally, what ldd doesn't show, is that the executable also expects a different runtime dynamic linker than what you have available on a normal linux system (/system/bin/linker instead of e.g. /lib/ld-linux.so.2). Also, don't expect being able to run the binaries if you'd just copy the listed libraries from the Android device - they would also have further requirements. In the end you'd end up with having almost a full Android environment anyway.

If you'd build an executable which doesn't use any of the android specific APIs, you would be able to link it statically, in which case you actually would be able to run it on your computer - but from the list of libraries you're linking to, I guess that's not the case.

Upvotes: 1

Related Questions