I just try to do a ndk-build for a simple hello program.
Android.mk file:
LOCAL_PATH:= $(call my-dir) # Get the local path of the project.
include $(CLEAR_VARS) # Clear all the variables with a prefix "LOCAL_"
LOCAL_SRC_FILES:=hello.cpp # Indicate the source code.
LOCAL_MODULE:= hello # The name of the binary.
LOCAL_ARM_MODE := arm
include $(BUILD_EXECUTABLE) # Tell ndk-build that we want to build a native executable.
Application.mk file:
APP_ABI := armeabi-v7a # Define the target architecture to be ARM.
APP_STL := gnustl_static
#APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions # This is the place you enable exception.
APP_PLATFORM = android-19
source file (hello.cpp):
#include <iostream>
int main(int argc, char* argv[])
{
std::cout<<"Hello from world!"<<std::endl;
for(int i=0; i<argc; ++i)
std::cout<<"Arg "<<i<<" is: "<<argv[i]<<std::endl;
return 0;
}
The ndk-build is success:
[armeabi-v7a] Compile++ arm : hello <= hello.cpp
[armeabi-v7a] Executable : hello
[armeabi-v7a] Install : hello => libs/armeabi-v7a/hello
But after I pushed this to the emulator and try to execute, I got this error: /system/bin/sh: ./hello: not executable: 32-bit ELF file
Check with file command and it shows as: file libs/armeabi-v7a/hello libs/armeabi-v7a/hello: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/bin/linker, stripped
Chck with readelf: readelf --file-header libs/armeabi-v7a/hello
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x3898
Start of program headers: 52 (bytes into file)
Start of section headers: 205324 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 26
Section header string table index: 25
So, what's wrong with my setting? Just can't figure out why. Thanks in advance.
An emulator can be configured to run only one kind of CPU ABI. It is possible that your emulator has been set to x86. Check to make sure that the ABI you are building in your Application.mk matches the one configured in your emulator. For example if your emulator is running x86:
Make sure your Application.mk file is also set to the same value:
APP_ABI := x86