i wrote a simple C++ Programm using NDK, and it works fine.
Now I want to add the following header file for using logging functions:
android\log.h
My Android.mk look like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS:= -llog
LOCAL_MODULE := ndkmodulea
LOCAL_SRC_FILES := ndkmodulea.cpp
include $(BUILD_SHARED_LIBRARY)
My .cpp file starts like this:
#include <jni.h>
#include <string.h>
#include <android\log.h>
if i try to run ndk-build (via terminal) inside the android project folder,
I'll get following error message:
Compile++ thumb : ndkmodulea <= ndkmodulea.cpp
jni/ndkmodulea.cpp:4:25: fatal error: android\log.h: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/ndkmodulea/ndkmodulea.o] Error 1
Can somebody help or teach me how to correctly include such header files?
Many thanks in advance!
Use forward slashes in #include paths:
#include <android/log.h>
Related
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.
I am currently reading the book "Beginning Android C++ Game Development" and after I import the source code, the headers do not work properly. It says that they are "unresolved inclusions" and cannot access them. Here is the source code for the top part:
#include <jni.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>
If I manually key in the location, I can access the include files (I would have to type in the full address for each header file in the above code); and I have gone to properties, Paths and Symbols, and included them (they were automatically included). Here is a copy of my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hellodroid
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Thanks for any help in advance.
Never Mind, I got it to work. I would suggest that instead of importing the source code to create the original project; create your own project and the settings using the book's steps. Then just cut and paste the main.cpp or hellodroid.cpp files into the project. Do not import the whole project or else the code probably will show errors.
I have a android program that has main logic written in NDK. But now I want to evaluate some python codes as part of main logic. So I tried to use this embed python in c http://docs.python.org/2/extending/embedding.html
I created a simple android project, with native.c like this (all I did was just adding python header)
#include <Python.h>
#include <jni.h>
#include <string.h>
#include <android/log.h>
#include <pthread.h>
#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"
void Java_com_example_com_test_mytest_MainActivity_helloLog(JNIEnv * env, jobject this, jstring logThis)
{
jboolean isCopy;
const char * szLogThis = (*env)->GetStringUTFChars(env, logThis, &isCopy);
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:LC: [%s]", szLogThis);
(*env)->ReleaseStringUTFChars(env, logThis, szLogThis);
}
Here is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog `python2.7-config --ldflags`
LOCAL_MODULE := ndk1
LOCAL_SRC_FILES := native.c
LOCAL_CFLAGS := `python2.7-config --cflags`
#LOCAL_SHARED_LIBRARIES := -lpthread
include $(BUILD_SHARED_LIBRARY)
I got following error when compiling (using Mac)
Compile thumb : ndk1 <= native.c
arm-linux-androideabi-gcc: error: i386: No such file or directory
arm-linux-androideabi-gcc: error: x86_64: No such file or directory
arm-linux-androideabi-gcc: error: unrecognized option '-arch'
arm-linux-androideabi-gcc: error: unrecognized option '-arch'
make: *** [obj/local/armeabi/objs/ndk1/native.o] Error 1
Anyone could help please? :D
Python2.7-config was built for a 64 bit i386 system not for Android. It's passing bad arguments to the compiler in the LOCAL_CFLAGS field. Either run one that you built to cross compile on Android or specify the values yourself. Check google for 'Python-For-Android' (Py4A) on how to embed python in an NDK app.
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/
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)