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

727 views Asked by At

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.

1

There are 1 answers

0
Thomas Colgrove On

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