I’m trying to build a wraper using some old C++ code in Android.
When compiling the errors bellow are shown:
In file included from /usr/local/android/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_algobase.h:61:0,
from /usr/local/android/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:63,
from /usr/local/android/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/map:60,
from /home/vocalize/source/xxxxxxxxxxxxxxxxxxxxx/Lxxxxxxx.h:9,
from /home/vocalize/source/xxxxxxxxxxxxxxxxx/jni/cxxx_wrap.c:3:
/usr/local/android/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/functexcept.h:43:1: error: unknown type name 'namespace'
/usr/local/android/android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/functexcept.h:44:1: error: expected ',' or ';' before '{' token
I’m using the following Makefile.mk
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(MY_LIB_DIR)include
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(BASE_PATH)
LOCAL_MODULE := cxxxx_lib
LOCAL_SRC_FILES := cxxxx_wrap.c
LOCAL_STATIC_LIBRARIES := my_lib
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
What I can do to fix these errors?
A C++ .h file is being included from
cxxx_wrap.c, which is a .c file. The compiler uses the extension of the source file to detect the language. So it’s assuming C, and choking on the C++-specific syntax.Rename cxxx_wrap.c to .cpp or .cxx. Or surround the
#include "Lxxxxxxx.h"line with#ifdef __cplusplus/#endif. Or force C++ compilation by specifying-x c++compiler option.Once you do, make sure all JNI methods in cxxx_wrap are declared with JNIEXPORT or surrounded with
extern "C" {}. Otherwise, the Java run-time won’t find them.For the record: renaming the .h file to .hpp won’t help.