21

I am trying to compile Taglib for Android. I have downloaded the latest version for Taglib from here . After compiling it for arm-linux build I have successfully imported it in my application, but when I try to call any function from tag_c.h I am getting following error:

SharedLibrary  : taglibwav.so
/home/test/workspacenew/Androidtaglibexample/obj/local/armeabi/
objs/squared/taglibwav.o: In function 
`Java_com_android_androidtag_WavFileDetails_taglibwav':
/home/test/workspacenew/Androidtaglibexample/jni/taglibwav.c:30: 
undefined reference to `taglib_set_strings_unicode'
collect2: ld returned 1 exit status
make: *** [/home/test/workspacenew/Androidtaglibexample/obj/
local/armeabi/taglibwav.so] Error 1

Application configuration information is:

Taglib ./configure :-

./configure CC="/home/hcl/taglib/taglib/toolchain/bin/arm-linux-androideabi-gcc"\
--host="arm-linux" \
--build="arm" \
--enable-static="no" \
--enable-shared="yes" \
--prefix="/home/test/workspacenew/Androidtaglibexample/jni/testtaglib/"\

Android.mk :-

LOCAL_PATH := $(call my-dir)

#declare the prebuilt library
include $(CLEAR_VARS)
LOCAL_MODULE := taglibtest
LOCAL_SRC_FILES := testtaglib/lib/libtag.a
LOCAL_EXPORT_C_INCLUDES := testtaglib/include/taglib/
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS) 
include $(call all-subdir-makefiles)
LOCAL_MODULE := taglibwav
LOCAL_SRC_FILES := taglibwav.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/testtaglib/include/taglib/
LOCAL_SHARED_LIBRARY := taglibtest
LOCAL_LDLIBS    := -llog -ljnigraphics -lz -lm -L$(SYSROOT)/usr/lib -llog 
include $(BUILD_SHARED_LIBRARY)


Application.mk :-
APP_ABI :=armeabi
APP_STL:=stlport_static


taglibwav.c :-
#include <jni.h>
#include <tag_c.h>
#include <android/log.h>
#ifndef FALSE
#define FALSE 0
#endif
.......
.......
JNIEXPORT void JNICALL Java_com_android_androidtag_WavFileDetails_taglibwav
  (JNIEnv * ev, jclass jc){
      int i;
      int seconds;
      int minutes;
      TagLib_File *file;  //<< accessed form tag_c.h : OK
      TagLib_Tag *tag;    //<< accessed form tag_c.h : OK
      const TagLib_AudioProperties *properties; //<<accessed form tag_c.h : OK
      taglib_set_strings_unicode(FALSE);//<<accessed form tag_c.h : GETTING ERROR
}
....
....

Android NDK Version :- Android-Ndk-r7c

Please, guide me in the right direction to fix what I'm doing wrong

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • 3
    I have never used TagLib, so I don't know if I can help. :( What is the error? – Sam Apr 08 '13 at 20:50
  • @Sam: i am getting `undefined reference to taglib_set_strings_unicode` error when accessing any function from `tag_c.h` . you can see [this example](https://github.com/taglib/taglib/blob/master/examples/tagreader_c.c) for reading all tags from any audio file which is running perfectly when i am compile it on Ubuntu with `gcc`. – ρяσѕρєя K Apr 08 '13 at 20:56
  • @ρяσѕρєяK I've been trying to work out how to use taglib on Android for months. If you had any luck with this, I'd love to have a brief discussion about it.. t.malseed@gmail.com -- Thanks for your time. – Tim Malseed Apr 30 '13 at 02:48
  • Did you ever find this out @ρяσѕρєяK? I am having the exact same problem! :( – Bitcoin Cash - ADA enthusiast Apr 28 '14 at 03:34

5 Answers5

9

I think you might need -ltag_c in there somewhere

Moog
  • 10,193
  • 2
  • 40
  • 66
  • Thanks for response. where i add `-ltag` ? i tried it with `LOCAL_LDLIBS` but im getting `/arm-linux-androideabi/bin/ld: cannot find -ltag` – ρяσѕρєя K Apr 08 '13 at 21:10
  • oops ... that should be `-ltag_c`, you may need to copy or link the library into that path – Moog Apr 08 '13 at 21:15
  • thanks, as you can see my `taglibwav.c` i am able to access `TagLib_File`,`TagLib_Tag` and `TagLib_AudioProperties` struct's from `tag_c.h` but when accessing any method im getting same error. – ρяσѕρєя K Apr 08 '13 at 21:19
  • 3
    I would imagine that's because this is a linker error. The structs are defined in the header, but only the prototype of the functions are defined there. – Moog Apr 08 '13 at 21:27
  • yes you are right. here is [bindings for taglib](https://github.com/taglib/taglib/tree/master/bindings) . how can i bind it. im not able to start bounding for this question before 2 days. please if you have any link, doc or example regarding how we use taglib in android then share it. VLC already using taglib for extracting tags from audio files – ρяσѕρєя K Apr 08 '13 at 21:34
  • 1
    If your linker says "cannot find -lany-library", also add -Lpath/to/the/library to the LOCAL_LDLIBS variable. – Peter Jankuliak Apr 12 '13 at 13:08
1
  TagLib_File *file;  //<< accessed form tag_c.h : OK
  TagLib_Tag *tag;    //<< accessed form tag_c.h : OK
  const TagLib_AudioProperties *properties; //<<accessed form tag_c.h : OK
  taglib_set_strings_unicode(FALSE);//<<accessed form tag_c.h : GETTING ERROR

The reason you can't access taglib_set_strings_unicode is because of how TAGLIB_C_EXPORT is defined in tag_c.h.

#if defined(_WIN32) || defined(_WIN64)
#ifdef MAKE_TAGLIB_C_LIB
#define TAGLIB_C_EXPORT __declspec(dllexport)
#else
#define TAGLIB_C_EXPORT __declspec(dllimport)
#endif
#elif defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 1)
#define TAGLIB_C_EXPORT __attribute__ ((visibility("default")))
#else
#define TAGLIB_C_EXPORT
#endif
...
typedef struct { int dummy; } TagLib_File;
typedef struct { int dummy; } TagLib_Tag;
typedef struct { int dummy; } TagLib_AudioProperties;
...
TAGLIB_C_EXPORT void taglib_set_strings_unicode(BOOL unicode);
...
Duke
  • 843
  • 1
  • 8
  • 10
  • May I ask who voted me down? Because http://stackoverflow.com/questions/15887838/taglib-for-android/15915306#16013411 is pretty much the same as my answer. – Duke May 26 '13 at 09:07
0

To get the job done I would hack tag_c.h at line 43 to define the proper visibility rules:

#define TAGLIB_C_EXPORT __attribute__ ((visibility("default")))

If this works, you might open a bug at taglib and link back to this question.

Giacomo Tesio
  • 7,144
  • 3
  • 31
  • 48
0
LOCAL_STATIC_LIBRARY := taglibtest

You are using static library, not shared. The directive to use shared one confuses the build environment.

Valeri Atamaniouk
  • 5,125
  • 2
  • 16
  • 18
0

You need to link both tag_c.h.o and taglibwav.o :

gcc -o program tag_c.h taglibwav.c
dharmendra
  • 7,835
  • 5
  • 38
  • 71