I need to build bspatch.c from bsdiff-4.3 to work on an android tablet running KitKat, but I keep getting the following errors.
puter#radio:~/newWorkspace/AndroidCode$ $NDK_ROOT/ndk-build
[armeabi] Compile thumb : bspatch <= bspatch.c
[armeabi] Executable : bspatch
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:119: error: undefined reference to 'BZ2_bzReadOpen'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:126: error: undefined reference to 'BZ2_bzReadOpen'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:133: error: undefined reference to 'BZ2_bzReadOpen'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:148: error: undefined reference to 'BZ2_bzRead'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:165: error: undefined reference to 'BZ2_bzRead'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:184: error: undefined reference to 'BZ2_bzRead'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:195: error: undefined reference to 'BZ2_bzReadClose'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:196: error: undefined reference to 'BZ2_bzReadClose'
/home/puter/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/bspatch/bspatch.o: in function main:jni/bspatch.c:197: error: undefined reference to 'BZ2_bzReadClose'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/bspatch] Error 1
Here is my Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bspatch.c
LOCAL_MODULE := bspatch
LOCAL_C_INCLUDES += /home/puter/android-ndk-r10c/sources/third_party/bzip2
LOCAL_STATIC_LIBRARIES := libbz2
include $(BUILD_EXECUTABLE)
This bug is documented in a number of places, e.g. https://bugs.launchpad.net/ubuntu/+source/bsdiff/+bug/726338, but I still don't know how to fix it. I work as a Junior Java Developer, but have no experience with C or C++, so any help would be much appreciated.
I found a workaround for anyone with a similiar issue.
I changed my Android.mk to
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := bspatch.c bzlib.c crctable.c randtable.c decompress.c huffman.c
LOCAL_MODULE := bspatch
LOCAL_C_INCLUDES := /home/puter/android-ndk-r10c/sources/third_party/bzip2/
include $(BUILD_EXECUTABLE)
and copied the source files with the methods causing the undefined errors in to the project's jni folder.
After that it builds fine
puter#radio:~/newWorkspace/AndroidCode$ /home/puter/android-ndk-r10c/ndk-build
[armeabi] Compile thumb : bspatch <= bspatch.c
[armeabi] Compile thumb : bspatch <= bzlib.c
[armeabi] Compile thumb : bspatch <= crctable.c
[armeabi] Compile thumb : bspatch <= randtable.c
[armeabi] Compile thumb : bspatch <= decompress.c
[armeabi] Compile thumb : bspatch <= huffman.c
[armeabi] Executable : bspatch
[armeabi] Install : bspatch => libs/armeabi/bspatch
Related
Why can I not find libmediandk.so with the following command in the Android.mk file:
LOCAL_LDLIBS += -lmediandk
Application.mk
NDK_TOOLCHAIN_VERSION := 4.9
APP_ABI := x86
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c++11
LOCAL_CFLAGS += -UNDEBUG
LOCAL_LDLIBS += -lmediandk
LOCAL_LDLIBS += -OpenMAXAL
LOCAL_LDLIBS += -landroid
LOCAL_SHARED_LIBRARIES += libmediandk
LOCAL_LDLIBS += -llog
CC=/home/c/Downloads/Openglxmlfour/i686-linux-android/bin/i686-linux-android-gcc
CXX=CC=/home/c/Downloads/Openglxmlfour/i686-linux-android/bin/i686-linux-android-g++
LOCAL_MODULE := native-codec-jni # name your module here.
LOCAL_SRC_FILES := native-codec-jni.cpp looper.cpp
LOCAL_C_INCLUDES=/home/c/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86/usr/include
include $(BUILD_SHARED_LIBRARY)
Command Line
ndk-build clean && ndk-build
[x86] Clean : native-codec-jni [x86]
[x86] Clean : stdc++ [x86]
[x86] Compile++ : native-codec-jni <= native-codec-jni.cpp
[x86] Compile++ : native-codec-jni <= looper.cpp
[x86] StaticLibrary : libstdc++.a
[x86] SharedLibrary : libnative-codec-jni.so
/home/c/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot find -lmediandk
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:94: error: undefined reference to 'AMediaCodec_dequeueInputBuffer'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:98: error: undefined reference to 'AMediaCodec_getInputBuffer'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:99: error: undefined reference to 'AMediaExtractor_readSampleData'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:105: error: undefined reference to 'AMediaExtractor_getSampleTime'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:108: error: undefined reference to 'AMediaCodec_queueInputBuffer'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:109: error: undefined reference to 'AMediaExtractor_advance'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:115: error: undefined reference to 'AMediaCodec_dequeueOutputBuffer'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:129: error: undefined reference to 'AMediaCodec_releaseOutputBuffer'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:137: error: undefined reference to 'AMediaCodec_getOutputFormat'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:138: error: undefined reference to 'AMediaFormat_toString'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:139: error: undefined reference to 'AMediaFormat_delete'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:172: error: undefined reference to 'AMediaExtractor_seekTo'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:173: error: undefined reference to 'AMediaCodec_flush'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:161: error: undefined reference to 'AMediaCodec_stop'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:162: error: undefined reference to 'AMediaCodec_delete'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:163: error: undefined reference to 'AMediaExtractor_delete'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:237: error: undefined reference to 'AMediaExtractor_new'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:240: error: undefined reference to 'AMediaExtractor_setDataSourceFd'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:247: error: undefined reference to 'AMediaExtractor_getTrackCount'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:275: error: undefined reference to 'AMediaFormat_delete'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:253: error: undefined reference to 'AMediaExtractor_getTrackFormat'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:254: error: undefined reference to 'AMediaFormat_toString'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:257: error: undefined reference to 'AMEDIAFORMAT_KEY_MIME'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:257: error: undefined reference to 'AMediaFormat_getString'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:263: error: undefined reference to 'AMediaExtractor_selectTrack'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:264: error: undefined reference to 'AMediaCodec_createDecoderByType'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:265: error: undefined reference to 'AMediaCodec_configure'
/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/jni/native-codec-jni.cpp:273: error: undefined reference to 'AMediaCodec_start'
collect2: error: ld returned 1 exit status
make: *** [/home/c/Downloads/android-ndk-master2/MyApplication/app/src/main/obj/local/x86/libnative-codec-jni.so] Error 1
libmediandk was first added to android-21 (https://android-review.googlesource.com/#/c/278674/1/media/ndk/Android.bp). You haven't stated an APP_PLATFORM in your Application.mk, so you're defaulting to android-9.
To get access to libmediandk, set APP_PLATFORM := android-21 in your Application.mk. Note that this will make Lollipop the minimum supported platform for your application.
I'm having some problems with compiling .cpp file with NDK. It seems not to be finding static library libIrmaMatrix. Any suggestions?
Here is my Android.mk
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
LOCAL_PATH := $(call my-dir)
#IrmaMatrixLib
include $(CLEAR_VARS)
LOCAL_MODULE := irmaMatrix
$(warning $(TARGET_ARCH_ABI))
LOCAL_SRC_FILES := iris/sensor-api/static/libIrmaMatrix.a
LOCAL_LDLIBS = -lz -lm -lc
include $(PREBUILT_STATIC_LIBRARY)
##BoostSystem
include $(CLEAR_VARS)
LOCAL_MODULE := libSystem
LOCAL_SRC_FILES := boost/lib/libboost_system-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
#libAtomic
include $(CLEAR_VARS)
LOCAL_MODULE := libAtomic
LOCAL_SRC_FILES := boost/lib/libboost_atomic-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
#libChrono
include $(CLEAR_VARS)
LOCAL_MODULE := libChrono
LOCAL_SRC_FILES := boost/lib/libboost_chrono-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
#libProgramOptions
include $(CLEAR_VARS)
LOCAL_MODULE := libProgramOptions
LOCAL_SRC_FILES := boost/lib/libboost_program_options-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
#libThread
include $(CLEAR_VARS)
LOCAL_MODULE := libThread
LOCAL_SRC_FILES := boost/lib/libboost_thread-gcc-mt-1_55.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_55
LOCAL_EXPORT_C_INCLUDE_DIRS += -I$(LOCAL_PATH)/boost/include/boost-1_55
LOCAL_EXPORT_C_INCLUDE_DIRS += -I$(LOCAL_PATH)/include/iris/sensor-api
LOCAL_EXPORT_C_INCLUDE_DIRS += -I$(LOCAL_PATH)/prebuild/static/libIrmaMatrix.a
LOCAL_MODULE := AVL
LOCAL_MODULE_FILENAME:= libAVL
LOCAL_SRC_FILES := AVL.cpp
LOCAL_STATIC_LIBRARIES := irmaMatrix
LOCAL_STATIC_LIBRARIES += libSystem
LOCAL_STATIC_LIBRARIES += libAtomic
LOCAL_STATIC_LIBRARIES += libThread
LOCAL_STATIC_LIBRARIES += libChrono
LOCAL_STATIC_LIBRARIES += libProgramOptions
LOCAL_LDLIBS := -lz -lm -lc
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := armeabi-v7a-hard
#APP_STL := stlport_static
APP_CFLAGS += -mfloat-abi=hard
APP_STL := gnustl_static
APP_MODULES := AVL
APP_PLATFORM := android-18
APP_CPPFLAGS := -frtti -fexceptions
Following errors:
[armeabi-v7a-hard] SharedLibrary : libAVL.so
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(Connection.o): in function iris::drivers::Connection::~Connection():Connection.cpp(.text+0x39c): error: undefined reference to '__assert_fail'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(Connection.o): in function iris::drivers::Connection::~Connection():Connection.cpp(.text+0x4a8): error: undefined reference to '__assert_fail'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(Connection.o): in function iris::drivers::Connection::~Connection():Connection.cpp(.text+0x5b4): error: undefined reference to '__assert_fail'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(Connection.o): in function iris::drivers::Connection::unregisterSensor(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):Connection.cpp(.text+0x77c): error: undefined reference to '__assert_fail'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(LogFile.o): in function iris::utilities::LogFile::readEntryAt(long long):LogFile.cpp(.text+0x208): error: undefined reference to 'std::basic_istream<char, std::char_traits<char> >::seekg(std::fpos<__mbstate_t>)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function iris::drivers::DriverManager::loadDrivers(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool):DriverManager.cpp(.text+0x1d8c): error: undefined reference to 'boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function iris::drivers::DriverManager::loadDrivers(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool):DriverManager.cpp(.text+0x1dec): error: undefined reference to 'boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function void boost::checked_delete<boost::filesystem::detail::dir_itr_imp>(boost::filesystem::detail::dir_itr_imp*):DriverManager.cpp(.text._ZN5boost14checked_deleteINS_10filesystem6detail11dir_itr_impEEEvPT_+0x1c): error: undefined reference to 'boost::filesystem::detail::dir_itr_close(void*&, void*&)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>::dispose():DriverManager.cpp(.text._ZN5boost6detail17sp_counted_impl_pINS_10filesystem6detail11dir_itr_impEE7disposeEv+0x20): error: undefined reference to 'boost::filesystem::detail::dir_itr_close(void*&, void*&)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&):DriverManager.cpp(.text._ZN5boost10filesystem18directory_iteratorC1ERKNS0_4pathE+0xb8): error: undefined reference to 'boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(DriverManager.o): in function boost::filesystem::detail::recur_dir_itr_imp::increment(boost::system::error_code*):DriverManager.cpp(.text._ZN5boost10filesystem6detail17recur_dir_itr_imp9incrementEPNS_6system10error_codeE+0x58): error: undefined reference to 'boost::filesystem::directory_entry::m_get_symlink_status(boost::system::error_code*) const'
............
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(utf8wchar.o): in function gcc_coding_to_coding(char const*, char const*, char const*, unsigned int, char*, unsigned int):utf8wchar.cpp(.text+0xd8): error: undefined reference to 'iconv'
/home/manevbg/Documents/android-sdks/android-ndk-r10/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/iris/sensor-api/static/libIrmaMatrix.a(utf8wchar.o): in function gcc_coding_to_coding(char const*, char const*, char const*, unsigned int, char*, unsigned int):utf8wchar.cpp(.text+0xe8): error: undefined reference to 'iconv_close'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a-hard/libAVL.so] Error 1
I'm using hard cause of error I get when I'm using only armeabi-v7a: uses VFP register arguments, output does not
Seems like linker is not able to find definitions of standard c++ library functions and also functions in boost library. Please check have to set library paths for boost and libIraMatrixcorrectly in Makefile,
LOCAL_STATIC_LIBRARIES := irmaMatrix
LOCAL_STATIC_LIBRARIES += libSystem
LOCAL_STATIC_LIBRARIES += libAtomic
LOCAL_STATIC_LIBRARIES += libThread
LOCAL_STATIC_LIBRARIES += libChrono
LOCAL_STATIC_LIBRARIES += libProgramOptions
Probably, You can do do something like below,
LOCAL_LDLIBS := -L/path/to/the/library
Use above settings for boost libraries and libIraMatrix. Hope it helps.
I face issues with writing a wrapper around a calling method. Here is my wrapper :
#include <jni.h>
#include <cassert>
#include <fstream>
#include "TextDetection.h"
#include <opencv/highgui.h>
#include <exception>
extern "C" {
JNIEXPORT int JNICALL Java_cgi_pi_detect() {
IplImage * byteQueryImage = loadByteImage ( "Image_utilisateur.png" );
if ( !byteQueryImage )
{
printf ( "couldn't load query image\n" );
return -1;
}
// Detect text in the image
IplImage * output = textDetection ( byteQueryImage, atoi(1));
cvReleaseImage ( &byteQueryImage );
cvSaveImage ( "Image_Tesseract.png", output );
cvReleaseImage ( &output );
return 0;
}
}
But when I try to compile the wrapper with the Android.mk, I got the error :
[armeabi] Compile++ thumb: wrapper <= wrapper.cpp
[armeabi] SharedLibrary : libwrapper.so
jni/wrapper.cpp:22: error: undefined reference to 'cvReleaseImage'
jni/wrapper.cpp:23: error: undefined reference to 'cvSaveImage'
jni/wrapper.cpp:24: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:29: error: undefined reference to 'cvConvertScale'
jni/FeaturesMain.cpp:50: error: undefined reference to 'cvLoadImage'
jni/FeaturesMain.cpp:56: error: undefined reference to 'cvCvtColor'
jni/FeaturesMain.cpp:62: error: undefined reference to 'cvLoadImage'
jni/FeaturesMain.cpp:68: error: undefined reference to 'cvCvtColor'
jni/FeaturesMain.cpp:70: error: undefined reference to 'cvGetSize'
jni/FeaturesMain.cpp:70: error: undefined reference to 'cvCreateImage'
jni/FeaturesMain.cpp:71: error: undefined reference to 'cvConvertScale'
jni/FeaturesMain.cpp:72: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:87: error: undefined reference to 'cvReleaseImage'
jni/FeaturesMain.cpp:88: error: undefined reference to 'cvSaveImage'
jni/TextDetection.cpp:132: error: undefined reference to 'cvSetZero'
jni/TextDetection.cpp:178: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:178: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:191: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:191: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:192: error: undefined reference to 'cvConvertScale'
jni/TextDetection.cpp:193: error: undefined reference to 'cvCvtColor'
jni/TextDetection.cpp:204: error: undefined reference to 'cvRectangle'
jni/TextDetection.cpp:231: error: undefined reference to 'cvGetSize'
jni/TextDetection.cpp:231: error: undefined reference to 'cvCreateImage'
jni/TextDetection.cpp:240: error: undefined reference to 'cvConvertScale'
jni/TextDetection.cpp:241: error: undefined reference to 'cvCvtColor'
jni/TextDetection.cpp:252: error: undefined reference to 'cvRectangle'
jni/boost/include/boost-1_53/boost/unordered/detail/unique.hpp:270: error: undefined reference to 'b
oost::throw_exception(std::exception const&)'
jni/TextDetection.cpp:299: error: undefined reference to 'cvCanny'
jni/TextDetection.cpp:300: error: undefined reference to 'cvSaveImage'
jni/TextDetection.cpp:306: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:311: error: undefined reference to 'cvSobel'
jni/TextDetection.cpp:312: error: undefined reference to 'cvSobel'
jni/TextDetection.cpp:313: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:314: error: undefined reference to 'cvSmooth'
jni/TextDetection.cpp:337: error: undefined reference to 'cvSaveImage'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libwrapper.so] Error 1
These methods are implemented in my other C++ files. Here is the Android.mk :
LOCAL_PATH := $(call my-dir)
# static library info
LOCAL_MODULE := Library
LOCAL_SRC_FILES := libSWT.a
include $(PREBUILT_STATIC_LIBRARY)
# wrapper info
include $(CLEAR_VARS)
LOCAL_MODULE := wrapper
LOCAL_C_INCLUDES := jni/opencv/include/
LOCAL_C_INCLUDES += jni/boost/include/boost-1_53
LOCAL_SRC_FILES := wrapper.cpp
LOCAL_STATIC_LIBRARIES := Library
include $(BUILD_SHARED_LIBRARY)
And this is how I get the libSWT.a :
LOCAL_PATH := $(call my-dir)
# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_core
LOCAL_SRC_FILES := opencv/lib/libopencv_core.a
include $(PREBUILT_STATIC_LIBRARY)
# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_highgui
LOCAL_SRC_FILES := opencv/lib/libopencv_highgui.a
include $(PREBUILT_STATIC_LIBRARY)
# static library info
include $(CLEAR_VARS)
LOCAL_MODULE := opencv_imgproc
LOCAL_SRC_FILES := opencv/lib/libopencv_imgproc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := SWT
LOCAL_STATIC_LIBRARIES := opencv_core \
opencv_highgui \
opencv_imgproc
LOCAL_C_INCLUDES := jni/opencv/include/
LOCAL_C_INCLUDES += jni/boost/include/boost-1_53
LOCAL_SRC_FILES := FeaturesMain.cpp \
TextDetection.cpp
include $(BUILD_STATIC_LIBRARY)
I thought because I compile the libSWT.a with OpenCV and Boost, I didn't have to specify them in the Android.mk ?
I have some problem linking the STL in my Native application. Linking fails with both map::operator[] and map::insert while succeeds with other map functions.
My Application.mk is :
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
APP_CPPFLAGS += -g3
APP_CPPFLAGS += -DDEBUG
APP_ABI := armeabi-v7a
APP_PLATFORM:=android-14
NDK_TOOLCHAIN_VERSION:=4.6
The native code contains two folder level. I created for each internal folder an Android.mk file to compile and generate a static library. I'm using std::map in the deepest folder. Android.mk looks like:
TEMP_PATH_REG := $(call my-dir)
LOCAL_PATH := $(TEMP_PATH_REG)
include $(call all-subdir-makefiles)
LOCAL_PATH := $(TEMP_PATH_REG)
include $(CLEAR_VARS)
LOCAL_MODULE := registration
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../glm/
LOCAL_SRC_FILES := registration_factory.cpp \
inertial.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_STATIC_LIBRARY)
$(call import-module,android/native_app_glue)
When I build the project i get the following errors:
~/.android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/libregistration.a(registration_factory.o): in function std::_Rb_tree<int, std::pair<int const, xmar::IRegistration*>, std::_Select1st<std::pair<int const, xmar::IRegistration*> >, std::less<int>, std::allocator<std::pair<int const, xmar::IRegistration*> > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair<int const, xmar::IRegistration*> const&):~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:1013: error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
StaticLibrary : libandroid_native_app_glue.a
rm -f obj/local/armeabi-v7a/libandroid_native_app_glue.a
~/.android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/libregistration.a(registration_factory.o): in function std::_Rb_tree_const_iterator<std::pair<int const, xmar::IRegistration*> >::operator--():~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:284: error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base const*)'
~/.android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-ar crs ./obj/local/armeabi-v7a/libandroid_native_app_glue.a ./obj/local/armeabi-v7a/objs-debug/android_native_app_glue/android_native_app_glue.o
~/.android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/libregistration.a(registration_factory.o): in function std::_Rb_tree_const_iterator<std::pair<int const, xmar::IRegistration*> >::operator++():~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:269: error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'
Prebuilt : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/
~/.android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi-v7a/libregistration.a(registration_factory.o): in function std::_Rb_tree_iterator<std::pair<int const, xmar::IRegistration*> >::operator--():~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_tree.h:203: error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
What I'm doig wrong?
Thanks a lot.
I found a workaround to compile the project.
LOCAL_LDLIBS += ~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libsupc++.a
LOCAL_LDLIBS += ~/.android-ndk-r8c/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a
I've successfully built some of the boost-libraries but when I include them in a test project I get link errors.
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : hello-jni <= test.cpp
SharedLibrary : libhello-jni.so
libboost_timer.a(cpu_timer.o): In function `~basic_iostream':
/opt/android-ndk-r7/sources/boost/../../sources/cxx-stl/gnu-libstdc++/include/istream:795: undefined reference to `VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
libboost_timer.a(cpu_timer.o): In function `show_time':
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `vtable for std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
libboost_timer.a(cpu_timer.o): In function `boost::timer::format(boost::timer::cpu_times const&, short, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:177: undefined reference to `std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()'
collect2: ld returned 1 exit status
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS = -fexceptions
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c test.cpp
LOCAL_STATIC_LIBRARIES := boost_timer, boost_system
LOCAL_LDLIBS := libboost_system.a libboost_timer.a libboost_chrono.a libboost_iostreams.a
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost)
And test.cpp
#include "test.hpp"
#include <string>
#include <boost/timer/timer.hpp>
void mytest() {
boost::timer::cpu_timer t;
}
we had very similar problem. What helped for us is to add -lgnustl_static at the end of the LOCAL_LDLIBS line in Android.mk. Like this:
LOCAL_LDIBS := -lboost_system .... -lgnustl_static
I think this is because boost libraries depend on STL but don't have it statically compiled in, so it needs to be mentioned explicitly like that.
Also, it seems you don't have to add the APP_STL := gnustl_static line to the Application.mk.