Running compiled file issue - eh_frame_hdr - android

I compiled simple file main.cpp using android-ndk-r8b:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("!!!Hello World!!!");
return EXIT_SUCCESS;
}
I used command as follow:
.../android-ndk-r8b/ndk-build APP_ABI=x86
from the directory of main.cpp file
My Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -fPIC
LOCAL_MODULE := main
LOCAL_SRC_FILES := main.cpp
include $(BUILD_EXECUTABLE)
Then I tried to open this file on debian x86 and I have this information:
./main: No such file or directory
then I used command:
ld main
and had information:
ld: error in main(.eh_frame); no .eh_frame_hdr table will be created.
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048320
Is it possible to run file compiled via android-ndk on a common linux x86 distribution?

No, the Android run-time libraries are not compatible with desktop Linux.
Note that your ndk-build puts the main executable in ./libs/x86/

Related

Building Android Command Line Executable with Prebuilt Shared Library

I'm trying to cross-compile an Android executable (command line) that calls a method inside a proprietary android prebuilt shared object (.so aarch64)
I'm using an Ubuntu 20.04 x86_64 and I want cross-compile an executable for Android 10 aarch64.
The method is defined from the relative JNI in the following way:
public static native int getScore();
I build a simple C program:
#include <stdio.h>
extern int getScore();
int main(){
getScore();
return(1);
}
Then I develop an Android.mk file like the following:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mygame
LOCAL_SRC_FILES := libmygame.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := getscore
LOCAL_SRC_FILES := getscore.c
LOCAL_SHARED_LIBRARIES := mygame
include $(BUILD_EXECUTABLE)
Then I try to compile with:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk
But I get the follwoing error:
./obj/local/arm64-v8a/objs/getscore/getscore.o: In function `main':
/tmp/cross-compile-test/./getscore.c:24: undefined reference to `getScore'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/mark01/Android/Sdk/ndk/21.3.6528147/build/core/build-binary.mk:738: obj/local/arm64-v8a/getscore] Error 1

ndk-build cannot find module with tag 'cxx-stl/system' in import path

I am a new learner of Android and I'm trying an android ndk demo with Ubuntu.
I run ndk-build and get the result below.
andylee#ubuntu:~/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/sources/hello/jni$ ndk-build -C
/home/andylee/Downloads/android-ndk-r11-linux-x86_64.tar.bz2/sources/hello
make: Entering directory '/home/andylee/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/sources/hello'
make: *** No rule to make target '/hello.c', needed by
'obj/local/armeabi/objs/helloARM/hello.o'. Stop.
make: Leaving directory '/home/andylee/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/sources/hello'
Then I delete the Android.mk in another folder (the folder structure is below) and get this.
andylee#ubuntu:~$ ndk-build -C /home/andylee/Downloads/android-ndk-r11-
linux-x86_64.tar.bz2/sources/hello
make: Entering directory '/home/andylee/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/sources/hello'
Android NDK: : Cannot find module with tag 'cxx-stl/system' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined
?
Android NDK: The following directories were searched:
Android NDK:
/home/andylee/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/build/core/setup-toolchain.mk:213: *** Android NDK: Aborting.
. Stop.
make: Leaving directory '/home/andylee/Downloads/android-ndk-r11-linux-
x86_64.tar.bz2/sources/hello'
My folder structure is like this.
home/andylee/Downloads/android-ndk-r11-linux-x86_64.tar.bz2
ndk-build
/sources
/cxx-stl
/system
/Android.mk
/hello
/jni
/hello.c
/hello.h
/Android.mk
Android.mk in jni folder
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := hello.c
LOCAL_MODULE := helloARM
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
hello.c
#include "hello.h"
int main(int argc, char *argv[]){
printf("Hello World!\n");
return 0;
}
hello.h
#ifndef HELLOHEADER_H_
#define HELLOHEADER_H_
#include <stdio.h>
#endif /*HELLOHEADER_H_*/
I wonder why ndk will find module with tag 'cxx-stl/system', I have not import any module in Android.mk. I've been frustrated with this for hours and I would really appreciate your help.
It seems that there is some syntax error when I copy those codes from the demo. After correcting the error I can successfully build.

How to use android-ndk?

I use PTAM code taken from here. I try to make an android application with this code.
The PTAM code uses libcvd, TooN, gvars3 library. I generate a .so file from my c++ test file using ndk-build.
Firstly, I try to run below code on android phone :
#include <string.h>
#include <jni.h>
extern "C" {
int returnInt()
{
int returnVal = 4;
return returnVal;
}
}
It can generate .so file without any errors. If I add #include < TooN/TooN.h > , `ndk-build says that
fatal error: TooN/TooN.h: No such file or directory
#include <TooN/TooN.h>
^
compilation terminated.
Android.mk is :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test-jni
LOCAL_SRC_FILES := test-jni.cpp
include $(BUILD_SHARED_LIBRARY)
How can I solve this error message?
fatal error: TooN/TooN.h: No such file or directory
#include <TooN/TooN.h>
When you use <> with #include, the compiler will search for the file in your include path (and possibly other predefined directories).
To add a directory to your include path when building a module in Android.mk you would add it to LOCAL__INCLUDES. For example, if the full path to TooN.h is /home/foobar/TooN/TooN.h you should do this:
LOCAL_C_INCLUDES += /home/foobar
I get fatal error: iostream: No such file or directory.There is no folder named iostream under usr/include or usr/local/include.
The iostream class is part of the STL, so you need to specify an STL implementation to build against. This can be done using the APP_STL variable in Application.mk. For example:
APP_STL := gnustl_shared
See this page for a list of STL implementations available with the NDK.

android NDK build issue

when I tried the NDK build command here is the error i got
D:\AndroidWorkSpace\cppTestProj>D:\android-ndk-r8b-windows\android-ndk-r8b\ndk-b
uild.cmd
Android NDK: WARNING: Unsupported source file extensions in jni/Android.mk for m
odule cppTestProj
Android NDK: LOCAL_SRC_FILES :=
"Compile++ thumb : cppTestProj <= maintestapp.cpp
jni/maintestapp.cpp:1:19: fatal error: iostream: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/cppTestProj/maintestapp.o] Error 1
The JNI folder has the following files:
maintestapp.cpp
Test_array_type.cpp
Test_array_type.h
Could u pls let me know the issue. Im not using Cygwin for the same. Am I missing any files?
Here is the make file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
here is the cpp file
#include<iostream>
#include"Test_array_type.h"
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
Test_array_type test_array;
Test_array_type *ptest_array1;
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList("Basha");
test_array.PrintList();
ptest_array1 = test_array.clonelist();
test_array.DeleteFromList(3);
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList(30);
test_array.AddToList(40);
test_array.AddToList(true);
test_array.AddToList("Java Beon APP");
test_array.PrintList();
ptest_array1->PrintList();
getch();
return true;
}
you should not run the 'ndk-build' command from your projects jni folder. To execute the Android.mk file run ndk-bild command within your root directory of project.
Your Android.mk should be look like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
Then run your ndk-build command
You can see this link for sample Android.mk file
Update:
static {
System.loadLibrary("hello-jni");
}
for more information please refer HelloJni.java file of sample project.
Thanks
you need to add LOCAL_C_INCLUDES and include your visual C++ include folders, since you are obviuosly working with it.

android external/stlport include in Android.mk build not successfull

I m trying to build an app with android-froyo source in which I am using skia and stl templates,
I have included
MY_INCLUDES=external/zlib external/jpeg external/freetype/include \
frameworks/base/core/jni/android/graphics external/skia/include/core \
external/libpng external/expat/lib <b>external/stlport/stlport</b>
libstlport_cflags := -D_GNU_SOURCE
libstlport_cppflags := -fuse-cxa-atexit
LOCAL_CPPFLAGS := $(libstlport_cppflags)
include $(BUILD_STATIC_LIBRARY)
I get the following error when i try to build the android source with this app, which i kept at packages/apps:
external/stlport/stlport/stl/_new.h:47:50: error: libstdc++/include/new: No such file or directory
Please guide me to rectify this issue.
Thanks
Mohit
As I understand the file which cannot be found by preprocessor is located in bionic folder.
I had the same issue and I solved it by adding the following line:
LOCAL_C_INCLUDES += bionic
I haven't tried this with Android 2.2 but I'm using Android Kitkat (4.4).
To get the stlport library working with our project we included it in our project's Android.mk as so:
include external/stlport/libstlport.mk
This is assuming that on Froyo, there is a libstlport.mk file to include in your build process. In 4.4, there is also a Android.mk file but that builds other code as well and builds stlport as a static library (which is not what we wanted).
You may need to also add the include directory as well, something like: external/stlport/stlport.
cpp
#include <stdio.h>
// The code
// The set of definitions and includes for STLPort
// They used defined() instead of #ifdef.
#define _STLP_HAS_INCLUDE_NEXT 1
#define _STLP_USE_MALLOC 1
#define _STLP_USE_NO_IOSTREAMS 1
#include <stl/config/_android.h>
#include <map>
#include <string>
int main(void)
{
std::string a = "abc";
printf("%s",a.c_str());
return 0;
}
Android.mk
# A simple test for the minimal standard C++ library
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test-libstl.cpp
LOCAL_C_INCLUDES += sources/cxx-stl/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
LOCAL_MODULE := test-libstl
include $(BUILD_EXECUTABLE)

Categories

Resources