2016-06-21 102 views
0

我只是嘗試爲一個簡單的hello程序做一個ndk-build。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的建造是成功:

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

但我推到這個模擬器後嘗試執行,我得到這個錯誤: /系統/ bin/sh的:./hello:不是可執行文件:32位ELF文件

請與文件命令,它顯示爲: libs/armeabi-v7a/hello libs/armeabi-v7a/hello:ELF 32位LSB共享對象,ARM,EABI5版本1(SYSV),動態鏈接,解釋器/系統/ bin /連接器,汽提

CHCK與readelf: readelf --file頭庫/ armeabi-V7A /你好

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

模擬器可以配置爲只運行一種CPU ABI。您的模擬器可能已設置爲x86。檢查以確保您在Application.mk中構建的ABI與仿真器中配置的匹配。例如,如果你的模擬器運行86:

enter image description here

確保您Application.mk文件也被設置爲相同的值:

APP_ABI := x86  
0

似乎它與模擬器有關的問題。推這到Android設備,它的工作原理。