ndk-build可执行文件未被识别为可执行文件

时间:2016-06-21 10:48:18

标签: android-ndk ndk-build

我只是尝试为简单的hello程序做一个ndk-build。

Android.mk文件:

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文件:

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

源文件(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;
}

ndk-build是成功的:

[armeabi-v7a] Compile++ arm  : hello <= hello.cpp
[armeabi-v7a] Executable     : hello
[armeabi-v7a] Install        : hello => libs/armeabi-v7a/hello

但是在我将其推送到模拟器并尝试执行之后,我收到了此错误: / system / bin / sh:./ hello:不可执行:32位ELF文件

使用file命令检查,它显示为: 文件libs / armeabi-v7a / hello libs / armeabi-v7a / hello:ELF 32位LSB共享对象,ARM,EABI5版本1(SYSV),动态链接,解释器/系统/ bin /链接器,剥离

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

那么,我的设置有什么问题?只是无法弄清楚原因。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

可以将仿真器配置为仅运行一种CPU ABI。您的模拟器可能已设置为x86。检查以确保您在Application.mk中构建的ABI与模拟器中配置的ABI相匹配。例如,如果您的模拟器正在运行x86:

enter image description here

确保您的Application.mk文件也设置为相同的值:

APP_ABI := x86    

答案 1 :(得分:0)

似乎与模拟器有关的问题。推送到Android设备,它可以工作。