ndk-build BUILD_EXECUTABLE 产生的文件不能被识别为executable
本人想通过ndk-build编译一个可执行文件直接push到手机上以root执行,照着网上的方法做了一下执行时发现编译出来的文件并不能被识别为可执行文件。
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;
}
编译过程:
[armeabi-v7a] Compile++ arm : hello <= hello.cpp
[armeabi-v7a] Executable : hello
[armeabi-v7a] Install : hello => libs/armeabi-v7a/hello
push到手机后root执行的错误: /system/bin/sh: ./hello: not executable: 32-bit ELF file
在Linux下用file命令查看:
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
请各位大神帮看下为什么会出现这种情况。谢谢。