Search Suggest

Cross compiler thư viện opensource

Trong bài này chúng ta sẽ ví dụ việc build và sử dụng thư viện taglib-1.5, thư viện này dùng để lấy thông tin của các file nhạc.

Các bước thực hiện:
- Giải nén taglib-1.5.tar.gz
- cd  terminal vào thư mục source code taglib-1.5
- export biến môi trường cross-compiler
 export PATH=$PATH:/opt/FriendlyARM/toolschain/4.4.3/bin   

- cấu hình configure
 ./configure --host=arm-none-linux-gnueabi --prefix=/friendlyarm/local \  
CC=arm-none-linux-gnueabi-gcc \
CXX=arm-none-linux-gnueabi-g++

 make  
make install


- example
Trong thư mục taglib-1.5/examples có nhiều ví dụ, chúng ta sẽ test thư viện với chương trình tagreader_c.c

   
#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);

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));

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;
}


- source biến môi trường đến thư mục đã install taglib:
DEPEND_LIB_DIR=/friendlyarm/local  
export CFLAGS="-I${DEPEND_LIB_DIR}/include -I${DEPEND_LIB_DIR}/include/taglib"
export CPPFLAGS=-I${DEPEND_LIB_DIR}/include
export LDFLAGS=-L${DEPEND_LIB_DIR}/lib
export PKG_CONFIG_PATH=${DEPEND_LIB_DIR}/lib/pkgconfig
export LD_LIBRARY_PATH=${DEPEND_LIB_DIR}/lib
export PATH=$PATH:${DEPEND_LIB_DIR}/bin:${DEPEND_LIB_DIR}/sbin
export LIBS="-ltag -ltag_c"

- build example
 arm-none-linux-gnueabi-gcc tagreader_c.c -o tagreader_c ${CFLAGS} ${LDFLAGS} ${LIBS}  

- Copy toàn bộ chương trình tagreader_c và thư viện taglib đã build vào thư mục NFS (hoặc sdcard), vd:


- Mở minicom, mount và cd vào thư mục NFS của taglib
 mount -o nolock,rsize=1024,wsize=1024 192.168.1.2:/friendlyarm/usr3 /friendlyarm  

- source biến môi trường của taglib, vd đường dẫn là /friendlyarm/taglib, tương tự như khi build chương trình tagreader_c vậy:

 DEPEND_LIB_DIR=/friendlyarm/taglib   
export CFLAGS="-I${DEPEND_LIB_DIR}/include -I${DEPEND_LIB_DIR}/include/taglib"
export CPPFLAGS=-I${DEPEND_LIB_DIR}/include
export LDFLAGS=-L${DEPEND_LIB_DIR}/lib
export PKG_CONFIG_PATH=${DEPEND_LIB_DIR}/lib/pkgconfig
export LD_LIBRARY_PATH=${DEPEND_LIB_DIR}/lib
export PATH=$PATH:${DEPEND_LIB_DIR}/bin:${DEPEND_LIB_DIR}/sbin
export LIBS="-ltag -ltag_c"

- chạy chương trình trên minicom

 [root@FriendlyARM taglib]# ./tagreader_c hanh_phuc_neu_co_em.mp3   
******************** "hanh_phuc_neu_co_em.mp3" ********************
-- TAG --
title - "H�á�º�¡nh Ph�Ã�ºc N�á�º�¿u Anh C�Ã�³ Em "
artist - "Ph�Ã�ºc b�á�»��“ "
album - "mp3.zing.vn"
year - "0"
comment - "Zing MP3 - Dinh cao am nhac"
track - "0"
genre - ""
-- AUDIO --
bitrate - 128
sample rate - 44100
channels - 2
length - 3:05




Đăng nhận xét