c - 使用 taglib 库函数中的 C 语言的音频文件的属性

标签 c audio taglib

我正在尝试使用 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 中的代码。不应该有任何方式使上述错误持续存在。

任何建议都会有用。

最佳答案

首先可以检查头文件“tag_c.h”的位置。在我的系统中,它的路径是“/usr/include/taglib”,因此我必须将包含头修改为:

#include <taglib/tag_c.h>

然后使用以下命令将代码与标签库链接来编译代码:

gcc -Wall tag.c -L/usr/include/taglib -ltag_c

关于c - 使用 taglib 库函数中的 C 语言的音频文件的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34409407/

相关文章:

jquery - 声音加载后,JQUERY更改属性

c++ - TagLib: 无法打开文件

c - 我在带有分隔符的文本文件中有一组值如何使用 C 编程修改值

在 cmocka 中临时启用和禁用函数包装的正确方法?

iphone - 如何在右耳机上播放音频,在左耳机上播放音乐?

grails - 动态在另一个自定义tagLib中调用自定义tagLib

jsp - 在 CQ5.6.1 项目中使用 Sling Taglib 1.3 版

c - "Correct"使用 GTK 为 g_signal_connect() 进行转换?

c - 当事先不知道输入大小但需要存储输入时,realloc 是在 C 中获取用户输入的唯一方法吗?

javascript - 使用 Web Audio API 的音频 react 视觉