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

Wenzhe

我只是尝试为一个简单的hello程序进行ndk构建。

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命令检查,它显示为:file libs / armeabi-v7a / hello libs / armeabi-v7a / hello:ELF 32位LSB共享对象,ARM,EABI5版本1(SYSV),动态链接,解释器/ system / bin /链接器,已剥离

带有readelf的Chck: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

那么,我的设置怎么了?只是不知道为什么。提前致谢。

霍皮亚

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

在此处输入图片说明

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

APP_ABI := x86    

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章