link opencv NDK library while compiling code with ndk toolchain
I'm trying to link the Opencv Prebuilt NDK libraries in a sample project composed of just a Makefile and a main.cpp.
The Makefile look like this:
ANDROID_NDK_ROOT=/home/XXX/libraries/android-ndk-r10c
CC=${ANDROID_NDK_ROOT}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
CFLAGS += --sysroot=${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm
CFLAGS += -frtti -fexceptions
CFLAGS += -I/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/
CFLAGS += -I/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2
CFLAGS += -I${ANDROID_NDK_ROOT}/sources/cxx-stl/stlport/stlport
CFLAGS += -I${ANDROID_NDK_ROOT}/sources/cxx-stl/system/include
CFLAGS += -I${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm/urs/include
LDFLAGS += -llog -lm -lz
LDLIBS += -L/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/libs/armeabi-v7a
LDLIBS += -L/home/XXX/libraries/OpenCV-2.4.10-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a
LDLIBS += -L${ANDROID_NDK_ROOT}/platforms/android-21/arch-arm/usr/lib
LDLIBS += -L$(SYSROOT)/usr/lib
SRCDIR = src
INCDIR = inc
OBJDIR = obj
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(INCDIR)/*.h)
OBJS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
CFLAGS += -I$(INCDIR)
EXEC=fastDragon
ARGS=
all:$(EXEC)
$(EXEC):$(OBJS)
$(CC) $(CFLAGS) -o $(EXEC) $(OBJS) $(LDFLAGS) $(LDLIBS)
$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c $< -o $@
clean:
$(RM) $(OBJS) *~ $(EXEC) $(SRCDIR)/*~
the main.cpp looks like this:
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"
int main (int argc, char** argv){
cv::Mat test;
return 0;
}
The compilation runs ok, but then when the linker tries to link all the libraries I get problems as if the libraries are not the correct one. The output looks like this:
obj/main.o:main.cpp:function main: error: undefined reference to '__cxa_end_cleanup'
obj/main.o:main.cpp:function cv::Mat::~Mat(): error: undefined reference to 'cv::fastFree(void*)'
obj/main.o:main.cpp:function cv::Mat::release(): error: undefined reference to 'cv::Mat::deallocate()'
obj/main.o(.ARM.extab+0x0): error: undefined reference to '__gxx_personality_v0'
collect2: error: ld returned 1 exit status