2
votes

I am trying to build a hello world executable for android. My test.c:

#include <stdio.h>
#include <stdlib.h>
int main()
{
     printf("Hello World\n");
     return 0;
}

My Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) 
# give module name
LOCAL_MODULE    := hello_world  
# list your C files to compile
LOCAL_SRC_FILES := test.c
# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)

My Application.mk:

APP_ABI := all

I ran ndk-build and I got 7 executables each in individual directory in libs - arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64 when I ran file command, I got

hello_world: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped

But when I pushed this to adb shell and execute it, I get an error:

not executable: magic 7F45.

What should I do to get this working?

1
The NDK is for building libraries, not standalone executables. - CommonsWare
Then why the option include $(BUILD_EXECUTABLE) is there in first place? - Raghuram Vadapalli
A library or an executable are the same. See in Wikipedia the format types. - eigenfield

1 Answers

-1
votes

ndk stands for native development kit. The term is used in to refer to tools used to interface platform independent code, eg: java, with native code.

In an Android context ndk refers to tools used to interface android java code with native code.

In all cases the interfacing will consist of the platform independent code calling into a library of some kind.

Thus ndk-build is used with an Android.mk file that has library only flags, eg: LOCAL_MODULE, and will only generate libraries since they are suited for this purpose.

For a static executable you're going to have to use this toolset more directly with a bona fida make file.