我正在尝试使用C语言找出音频文件的属性(艺术家姓名,标题,持续时间),这可以通过安装taglib(特别是 libtagc0-dev )来完成。在library中提供的一个示例中,给出了以下代码:
#include <stdio.h>
#include <tag_c.h>
#ifndef FALSE
#define FALSE 0
#endif
int main(int argc, char *argv[])
{
int i;
int seconds;
int minutes;
TagLib_File *file;
TagLib_Tag *tag;
const TagLib_AudioProperties *properties;
taglib_set_strings_unicode(FALSE);
for(i = 1; i < argc; i++) {
printf("******************** \"%s\" ********************\n", argv[i]);
file = taglib_file_new(argv[i]);
if(file == NULL)
break;
tag = taglib_file_tag(file);
properties = taglib_file_audioproperties(file);
if(tag != NULL) {
printf("-- TAG --\n");
printf("title - \"%s\"\n", taglib_tag_title(tag));
printf("artist - \"%s\"\n", taglib_tag_artist(tag));
printf("album - \"%s\"\n", taglib_tag_album(tag));
printf("year - \"%i\"\n", taglib_tag_year(tag));
printf("comment - \"%s\"\n", taglib_tag_comment(tag));
printf("track - \"%i\"\n", taglib_tag_track(tag));
printf("genre - \"%s\"\n", taglib_tag_genre(tag));
}
if(properties != NULL) {
seconds = taglib_audioproperties_length(properties) % 60;
minutes = (taglib_audioproperties_length(properties) - seconds) / 60;
printf("-- AUDIO --\n");
printf("bitrate - %i\n", taglib_audioproperties_bitrate(properties));
printf("sample rate - %i\n", taglib_audioproperties_samplerate(properties));
printf("channels - %i\n", taglib_audioproperties_channels(properties));
printf("length - %i:%02i\n", minutes, seconds);
}
taglib_tag_free_strings();
taglib_file_free(file);
}
return 0;
}
然而,当我编译代码时,我收到以下错误:
/tmp/ccz8cuR1.o: In function `main':
tag.c:(.text+0x15): undefined reference to `taglib_set_strings_unicode'
tag.c:(.text+0x69): undefined reference to `taglib_file_new'
tag.c:(.text+0x85): undefined reference to `taglib_file_tag'
tag.c:(.text+0x95): undefined reference to `taglib_file_audioproperties'
tag.c:(.text+0xba): undefined reference to `taglib_tag_title'
tag.c:(.text+0xd8): undefined reference to `taglib_tag_artist'
tag.c:(.text+0xf6): undefined reference to `taglib_tag_album'
tag.c:(.text+0x114): undefined reference to `taglib_tag_year'
tag.c:(.text+0x131): undefined reference to `taglib_tag_comment'
tag.c:(.text+0x14f): undefined reference to `taglib_tag_track'
tag.c:(.text+0x16c): undefined reference to `taglib_tag_genre'
tag.c:(.text+0x195): undefined reference to `taglib_audioproperties_length'
tag.c:(.text+0x1d4): undefined reference to `taglib_audioproperties_length'
tag.c:(.text+0x20c): undefined reference to `taglib_audioproperties_bitrate'
tag.c:(.text+0x229): undefined reference to `taglib_audioproperties_samplerate'
tag.c:(.text+0x246): undefined reference to `taglib_audioproperties_channels'
tag.c:(.text+0x273): undefined reference to `taglib_tag_free_strings'
tag.c:(.text+0x27f): undefined reference to `taglib_file_free'
collect2: error: ld returned 1 exit status
似乎库无法找到上述错误中提到的功能。我无法找到消除这些错误的方法,而且,因为我只是复制并粘贴了reference中的代码,所以不应该有任何方式导致上述错误持续存在。
任何建议都会有用。
答案 0 :(得分:0)
首先可以检查标题文件的位置&#39; tag_c.h&#39;。在我的系统中,它的路径是&#39; / usr / include / taglib&#39;因此我不得不将include标题修改为:
#include <taglib/tag_c.h>
然后使用以下命令将代码链接到标记库来编译代码:
gcc -Wall tag.c -L/usr/include/taglib -ltag_c