I'm using Archlinux and I have a simple C++ file main.cpp:
#include <iostream>
int main()
{
std::cout << "Hello world\n";
return 0;
}
I would like to compile it to run on Android.
I download Android NDK zip file, I extract it, and I follow the instructions on the official website https://developer.android.com/ndk/guides/other_build_systems#non-autoconf_make_projects
I run:
export NDK=/home/myuser/dnsmasq-Android/android-ndk-r26b/
export ANDROID_NDK=$NDK
export NDK_PROJECT_PATH=$NDK
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export PATH=$TOOLCHAIN/bin:$PATH
export TARGET=armv7a-linux-androideabi
export API=34
The path $TOOLCHAIN/bin now gives me access to the compiler executable armv7a-linux-androideabi34-clang++.
But if I run armv7a-linux-androideabi34-clang++ main.cpp, I get the error:
clang-17: error: no input files
What am I doing wrong?
UPDATE:
I tried another way: Inside the ./android-ndk-r26b extracted folder, I create a jni folder. Inside it I put 3 files: The main.cpp above, Application.mk containing:
APP_ABI := armeabi-v7a
# x86 # mips
APP_PLATFORM := android-33
#APP_STL := stlport_static
And Android.mk containing:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
#CFLAGS += -fvisibility=default -fPIE
#LDFLAGS += -rdynamic -fPIE -pie
# give module name
LOCAL_MODULE := hello_world
# list your C files to compile
LOCAL_SRC_FILES := main.cpp
# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)
Now inside ./android-ndk-r26b/jni I run the command:
../ndk-build
The terminal hangs and nothing happened. I tried leaving it for an hour but nothing changed. It seems like it is stuck..
I can't solve this either..