jeudi 19 mars 2015

Convert Makefile to Android.mk


I have a given c++ projects with a JNI interface and a makefile which creates a shared library that can be called successful from a Java application. Everything is working fine by using pure Java in Ubuntu.


Now I want to execute the JNI call from an Android application so I have to build the c++ shared library for Android and here is my problem because I am not very familiar with C++ and makefiles.


My first step was to build a simple c++ test project with just 2 classes with standard arithmetic operations to get familiar with the process. Everything was working fine and i could execute the native operations from my Android application.


And now my current step is to build a shared library from the given c++ project which can be built by makefile but not via Android.mk


The makefile looks like the following part:



JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
MY_INCLUDES=./
CC=g++
ARCH = $(shell uname -m)
CFLAGS=-c -fPIC -D$(ARCH) -DOS_LINUX -Wall

all: libSteering

clean:
rm obj/*.o libSteering.so

# the shared library
libSteering: Steering.o customizestub-JNI.o objs.o linwin.o qflite.o csocketclass.o ioclass.o ioportclass.o
$(CC) obj/Steering.o obj/customizestub-JNI.o obj/objs.o obj/linwin.o obj/qflite.o obj/csocketclass.o \
obj/ioclass.o obj/ioportclass.o -shared -lrt -o libSteering.so

# The JNI file needs Java includes as well
Steering.o: Steering.cpp Steering.h
$(CC) $(CFLAGS) Steering.cpp -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(MY_INCLUDES) -o obj/Steering.o

# the rest of the CAPI source files
customizestub-JNI.o: customizestub-JNI.cpp
$(CC) $(CFLAGS) customizestub-JNI.cpp -I$(MY_INCLUDES) -o obj/customizestub-JNI.o
objs.o: shared/sw/api/src/objs.cpp
$(CC) $(CFLAGS) shared/sw/api/src/objs.cpp -I$(MY_INCLUDES) -o obj/objs.o
# special hack for Linwin, so it doesn't call clokc_gettime()
linwin.o: shared/sw/src/linwin.cpp
$(CC) $(CFLAGS) -DELDK -I$(MY_INCLUDES) shared/sw/src/linwin.cpp -o obj/linwin.o
qflite.o: shared/sw/src/qflite.cpp
$(CC) $(CFLAGS) -I$(MY_INCLUDES) shared/sw/src/qflite.cpp -o obj/qflite.o
csocketclass.o: shared/sw/io/src/csocketclass.cpp
$(CC) $(CFLAGS) -I$(MY_INCLUDES) shared/sw/io/src/csocketclass.cpp -o obj/csocketclass.o
ioclass.o: shared/sw/io/src/ioclass.cpp
$(CC) $(CFLAGS) -I$(MY_INCLUDES) shared/sw/io/src/ioclass.cpp -o obj/ioclass.o
ioportclass.o: shared/sw/io/src/ioportclass.cpp
$(CC) $(CFLAGS) -I$(MY_INCLUDES) shared/sw/io/src/ioportclass.cpp -o obj/ioportclass.o


I created the following Android.mk



LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := Steering.cpp customizestub-JNI.cpp shared/sw/api/src/objs.cpp shared/sw/src/linwin.cpp shared/sw/src/qflite.cpp shared/sw/io/src/csocketclass.cpp shared/sw/io/src/ioclass.cpp shared/sw/io/src/ioportclass.cpp
LOCAL_MODULE := Steering
include $(BUILD_SHARED_LIBRARY)


I got directly some compilation errors that tells me that member variables and getter methods are not defined. So I think I have some problems with the includes. Maybe anybody can help we.


Thank you very much




Aucun commentaire:

Enregistrer un commentaire