Failing to link against libjpeg.so in jni/ndk shared library - android

Heya,
I'm having trouble building an ndk/jni shared library which I have developed. I am hoping to reuse the libjpeg which ships with the platform (/system/lib/libjpeg.so) however I cannot get it to link. When I build my shared library I get...
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:94: undefined reference to `jpeg_std_error(jpeg_error_mgr*)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:96: undefined reference to `jpeg_CreateDecompress(jpeg_decompress_struct*, int, unsigned int)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:98: undefined reference to `jpeg_stdio_src(jpeg_decompress_struct*, __sFILE*)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:100: undefined reference to `jpeg_read_header(jpeg_decompress_struct*, int)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:102: undefined reference to `jpeg_start_decompress(jpeg_decompress_struct*)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:124: undefined reference to `jpeg_read_scanlines(jpeg_decompress_struct*, unsigned char**, unsigned int)'
/home/blink/workspace_android2/HackBitmapJNI/jni/jnijpeg/JNIBmp.cpp:130: undefined reference to `jpeg_destroy_decompress(jpeg_decompress_struct*)'
collect2: ld returned 1 exit status
make: *** [/home/blink/workspace_android2/HackBitmapJNI/obj/local/armeabi/libjnijpeg.so] Error 1*
Which is essentially every symbol I would need to resolve out of libjpeg.so at runtime...
I have copied libjpeg.so off of my emulator and into my project directory under 'lib'. When I run 'arm-eabi-readelf -s' on that copy of libjpeg.so I can see all of the above symbols defined (I can't see method signatures.. just names.. is there a way to dump signatures/namespaces??)
My Android.mk is as follows...
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := /opt/android_src/dalvik/libnativehelper/include/nativehelper \
/opt/android_src/frameworks/base/include \
/opt/android_src/system/core/include \
/opt/android_src/dalvik/libnativehelper/include \
/opt/android_src/external/stlport/stlport \
/opt/android_src/external/jpeg \
/opt/android_src/bionic
LOCAL_LDFLAGS += -Llib
LOCAL_MODULE := jnijpeg
LOCAL_SRC_FILES := JNIBmp.cpp
LOCAL_LDLIBS := -lm -llog -ljpeg -landroid_runtime
include $(BUILD_SHARED_LIBRARY)
Thank you much for any help!

Try to use #include in this form:
extern "C" {
#include "jpeglib.h"
}
It worked for me.
Good luck!

I was able to link against -ljpeg using the following:
LOCAL_LDLIBS := -L$(MYDROID)/out/target/product/generic/system/lib/ -ljpeg

Related

Using the glib on Android : undefined reference to 'g_thread_init'

I am trying to compile a module for android using the ndk. The library has a dependency on glib, so I built that using https://github.com/ieei/glib, and everything seemed ok. However, when I try to use the glib module in my Android.mk file I get the following on running ndk-build:
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_cmd.c:1837: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_event.c:647: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_midi_router.c:106: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_sys.h:161: error: undefined reference to 'g_thread_init'
I looked up solutions to this problem, and I found this: http://ragnermagalhaes.blogspot.com/2007/09/undefined-reference-to-gthreadinit.html, but couldn't seem to get either of the proposed solutions to do anything for me (possibly because I am pretty new to the whole makefile thing)
My Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../PdCore/jni/libpd/pure-data/src \
$(LOCAL_PATH)/../glib \
$(LOCAL_PATH)/../glib/glib \
$(LOCAL_PATH)/../glib/gnulib \
$(LOCAL_PATH)/../glib/android \
$(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/include/fluidsynth \
$(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/include
LOCAL_MODULE := soundfonts
LOCAL_CFLAGS := -DPD
LOCAL_CFLAGS += -std=c11
LOCAL_CFLAGS += -w
LOCAL_CFLAGS +=
FLUID_SRC := $(wildcard $(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/src/*.c)
LOCAL_SRC_FILES := $(FLUID_SRC:$(LOCAL_PATH)/%=%) \
soundfonts.c
LOCAL_LDLIBS := $(LOCAL_PATH)/../glib/libs/armeabi/libglib-2.0.so
LOCAL_LDLIBS += -L$(LOCAL_PATH)/../PdCore/libs/$(TARGET_ARCH_ABI) -lpd -lgthread-2.0 -lglib-2.0
include $(BUILD_SHARED_LIBRARY)
Anybody have ideas for how to get rid of the linker errors? Thanks.
I figured it out! There are actually several shared object libraries being created when you build glib, and the one I was missing was libgthread-2.0.so.
I added libgthread-2.0.so to my LOCAL_LDLIBS and it worked

Using Boost for Android throws error while compiling

This is the error I get when using Boost library for Android. I am using Android NDK r8e and boost 1.53 and followed this tutorial.
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lgnustl_static
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1508: error: undefined reference to 'std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1508: error: undefined reference to 'std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1516: error: undefined reference to 'std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1532: error: undefined reference to 'std::__detail::_List_node_base::_M_unhook()'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libusit.so] Error 1
This is how my make file looks like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ./jni/opencv/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := usit
LOCAL_SRC_FILES := cr.cpp
LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_53
LOCAL_LDLIBS += -L$(LOCAL_PATH)/boost/lib/ -lboost_system-gcc-mt-1_53 -lboost_regex-gcc-mt-1_53 -lboost_filesystem-gcc-mt-1_53 -lboost_date_time-gcc-mt-1_53 \
-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \
-lgnustl_static
include $(BUILD_SHARED_LIBRARY)
As suggested in the tutorial I am specifying the path to NDK Root. I am using Ubuntu 12.04 and defined the NDK_ROOT variable in .bashrc and .profile like this:
export NDK_ROOT=${HOME}/android-ndks/android-ndk-r8e
I appreciate any help.
EDIT:
This is my Application.mk
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
APP_OPTIM := debug
NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
To use gnustl (static or shared), you need parameter APP_STL. Usually, we set it in Application.mk, but you can also set it on command line (do this with care, never mix different values).
I recommend to install the latest NDK, and not use the outdated 4.6 toolchain.
Example of Application.mk:
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS := -std=c++11

pthread error in ndk-build

Hi
I had try to compile the following Android.mk file using ndk-build.
I got the following errors. how can I resolve this problem?
please help me.
the make file is
# ================================================== ========
# NOTE:
# when executing binary, set LD_LIBRARY_PATH in device
# ================================================== ========
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
BASEDIR := ../../..
DISTDIR := ../../../..
LOCAL_MODULE := EvaluateFingerQuality
LOCAL_ARM_MODE := arm
# Includes
LOCAL_C_INCLUDES += \
$(BASEDIR)/Common/C \
$(DISTDIR)/Include
# Source files
LOCAL_SRC_FILES := \
$(BASEDIR)/Common/C/Utils.c \
EvaluateFingerQuality.c
LOCAL_LDLIBS += \
-Wl,-z,muldefs -Wl,-rpath=$(DISTDIR)/Lib/Android_$(TARGET_ARCH_ABI) \
-L $(DISTDIR)/Lib/Android_$(TARGET_ARCH_ABI) \
-lNLicensing -lNBiometricTools -lNBiometrics -lNMedia -lNCore -lc
include $(BUILD_EXECUTABLE)
the error is
$ ndk-build
Compile arm : EvaluateFingerQuality <= Utils.c
Compile arm : EvaluateFingerQuality <= EvaluateFingerQuality.c
Executable : EvaluateFingerQuality
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_trywrlock'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_rdlock'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_tryrdlock'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_wrlock'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `dladdr'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_destroy'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_init'
../../../../Lib/Android_armeabi/libNCore.so: undefined reference to `pthread_rwlock_unlock'
collect2: ld returned 1 exit status
/cygdrive/d/android-ndk-r8-windows/android-ndk-r8/build/core/build-binary.mk:381: recipe for target `/cygdrive/d/MegaMatcher_Embedded_1_2_SDK_Trial_for_Android/Tutorials/BiometricTools/C/obj/local/armeabi/EvaluateFingerQuality' failed
make: *** [/cygdrive/d/MegaMatcher_Embedded_1_2_SDK_Trial_for_Android/Tutorials/BiometricTools/C/obj/local/armeabi/EvaluateFingerQuality] Error 1
Android supports pthreads strating from API 9 version. i got the above error due to i am using old version of NDK. to avoid this build like this "$ndk-build APP_PLATFORM=android-9 "

cocos2dx eclipse: Various "error: undefined reference to "

I'm tryng to port an iOS game to Android platform with cocos2dx 2.0.4.
The core of the game is written in c++ and we managed to run it on iOS, in fact the game is avaivable on the Apple Store.
I'm using NDK r8d and lastest SDK, but I'm encountering a lot of issues when trying to build.
My application.mk is like this:
APP_STL := stlport_shared
APP_CPPFLAGS := -frtti
NDK_TOOLCHAIN_VERSION=4.7
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
ifdef STLG
LOCAL_MODULE := stlport_stlg
else
LOCAL_MODULE := stlport
endif
LOCAL_CFLAGS += -D__ANDROID__ \
-isystem $(SYSROOT)/usr/include \
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_CPPFLAGS += -fexceptions
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes $(LOCAL_PATH)/../../../../Box2D $(LOCAL_PATH)/../../../../cocos2dx $(LOCAL_PATH)/../../../../
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)
Here's the console log (only errors displayed):
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_alloc.h:158: error: undefined reference to 'std::__node_alloc::_M_allocate(unsigned int&)'
make: Leaving directory `/Users/arianna/android/cocos2d-2.0-x-2.0.4/grannnnnnny/proj.android'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_alloc.h:161: error: undefined reference to 'std::__node_alloc::_M_deallocate(void*, unsigned int)'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_string.c:600: error: undefined reference to 'std::__stl_throw_length_error(char const*)'
/Users/arianna/android/cocos2d-2.0-x-2.0.4/grannnnnnny/proj.android/../../cocos2dx/actions/CCActionInterval.cpp:386: error: undefined reference to '__dynamic_cast'
/Users/arianna/android/cocos2d-2.0-x-2.0.4/grannnnnnny/proj.android/../../cocos2dx/actions/CCActionInterval.cpp:1783: error: undefined reference to '__dynamic_cast'
/Users/arianna/android/cocos2d-2.0-x-2.0.4/grannnnnnny/proj.android/../../cocos2dx/actions/CCActionInterval.cpp:1838: error: undefined reference to '__dynamic_cast'
/Users/arianna/android/cocos2d-2.0-x-2.0.4/grannnnnnny/proj.android/../../cocos2dx/actions/CCActionInterval.cpp:1906: error: undefined reference to '__dynamic_cast'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_vector.c:41: error: undefined reference to 'std::__stl_throw_length_error(char const*)'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_vector.c:45: error: undefined reference to 'std::__stl_throw_out_of_range(char const*)'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_string.c:604: error: undefined reference to 'std::__stl_throw_out_of_range(char const*)'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_vector.c:41: error: undefined reference to 'std::__stl_throw_length_error(char const*)'
./obj/local/armeabi/libcocos2d.a(CCDirector.o):CCDirector.cpp:function typeinfo for cocos2d::CCDirector: error: undefined reference to 'vtable for __cxxabiv1::__vmi_class_type_info'
/Users/arianna/android/android-ndk-r8d/sources/cxx-stl/stlport/stlport/stl/_vector.c:41: error: undefined reference to 'std::__stl_throw_length_error(char const*)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/libgame.so] Error 1
Any help much appreciated, thanks...
Try this in application.mk APP_STL := gnustl_static?
You get the above undefined reference error because you have not added the necessary libraries in Android.mk files. It looks something like this
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/$(TARGET_ARCH_ABI)) \
-lcocos2d -lGLESv1_CM -llog -lgame_logic
I am stuck with this issue even after adding the libraries. Its got something to do with setting path but I dont know how to..
If you solve this let me know

OpenCV2.4 with Android Native Activity

I am currently facing the same problem than presented in this question, except that I use the 2.4 version in stead of the 2.3.1.
I've converted native-activity (from ndk samples) to c++ and modified android.mk and application.mk.
I had the same errors (with ~Mat and so one).
When I read the answers to the question, I realised I needed to add OPENCV_INSTALL_MODULES:=on and OPENCV_LIB_TYPE:=STATIC (which is strange since I have an other project with native openCV which does not require theese two lines).
But it's still not working.
Android.mk is the following :
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=STATIC
OPENCV_INSTALL_MODULES:=on
include includeOpenCV.mk
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#try to load OpenCV.mk from default install location
include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE := native-activity
LOCAL_SRC_FILES := main.cpp engine.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES += android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
I'm getting the following errors :
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvPuts(CvFileStorage*, char const*)':
persistence.cpp:(.text._ZL7icvPutsP13CvFileStoragePKc+0x20): undefined reference to `gzputs'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvGets(CvFileStorage*, char*, int)':
persistence.cpp:(.text._ZL7icvGetsP13CvFileStoragePci+0x26): undefined reference to `gzgets'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `icvXMLSkipSpaces(CvFileStorage*, char*, int)':
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x1e2): undefined reference to `gzgets'
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x208): undefined reference to `gzeof'
persistence.cpp:(.text._ZL16icvXMLSkipSpacesP13CvFileStoragePci+0x33c): undefined reference to `gzeof'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `_ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3':
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x124): undefined reference to `gzgets'
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x170): undefined reference to `gzeof'
/cygdrive/d/soft/NVPACK/android-ndk-r7c/build/core/build-binary.mk:366: recipe for target `obj/local/armeabi-v7a/libnative-activity.so' failed
persistence.cpp:(.text._ZL16icvYMLSkipSpacesP13CvFileStoragePcii.clone.3+0x28e): undefined reference to `gzeof'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvReleaseFileStorage':
persistence.cpp:(.text.cvReleaseFileStorage+0x24): undefined reference to `gzclose'
./obj/local/armeabi-v7a/libopencv_core.a(persistence.cpp.o): In function `cvOpenFileStorage':
persistence.cpp:(.text.cvOpenFileStorage+0x66e): undefined reference to `gzopen'
persistence.cpp:(.text.cvOpenFileStorage+0x8fc): undefined reference to `gzclose'
persistence.cpp:(.text.cvOpenFileStorage+0xaea): undefined reference to `gzrewind'
persistence.cpp:(.text.cvOpenFileStorage+0xbee): undefined reference to `gzrewind'
persistence.cpp:(.text.cvOpenFileStorage+0xc0a): undefined reference to `gzclose'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libnative-activity.so] Error 1
Is there anything I missed ?
Although this is an old question, I run into the same issue and fixed it by adding
LOCAL_LDLIBS += -lz # Compression library
To my Android.mk
Try to replace
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM
with
LOCAL_LDLIBS += -llog -landroid -lEGL -lGLESv1_CM
I ended trying with the native plasma project (in which the display is done by writing in a bitmap) and it worked well.
Maybe GLES was messing with OpenCV. I don't think there is any other difference between the two projects.
In a way the problem is solved. Still, if anyone encounters the same issue and solved it, I would be interested to understand what caused it and how to fix it.

Categories

Resources