Showing posts with label FriendlyARM. Show all posts
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
- cấu hình configure
- 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
- source biến môi trường đến thư mục đã install taglib:
- build example
- 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
- 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:
- chạy chương trình trên minicom
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
Chương trình ứng dụng đầu tiên Helloworld
1. Build source code
helloworld.c
Export biến môi trường PATH đến cross-compiler:
Chương trình helloworld được build cho board arm, vì thế nếu bạn cố tình chạy nó trên host (x86) thì sẽ không được:
2. Run application
- Copy chương trình ra SDCard
- Khởi động board cùng với sdcard được gắn vào
- SDCard trên board sẽ được mount vào thư mục /sdcard
- cd vào thư mục có helloworld trên sdcard
- Chạy chương trình
Cách copy lên sdcard tỏ ra hơi mất công, nên cách tốt nhất hay được dùng khi develop chương trình là dùng mount NFS đã được đề cập ở bài trước.
helloworld.c
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello world ! \n");
return 1;
}
Export biến môi trường PATH đến cross-compiler:
export PATH=$PATH:/opt/FriendlyARM/toolschain/4.4.3/bin
arm-none-linux-gnueabi-gcc helloworld.c -o helloworld
Chương trình helloworld được build cho board arm, vì thế nếu bạn cố tình chạy nó trên host (x86) thì sẽ không được:
$ ./helloworld
bash: ./helloworld: cannot execute binary file
2. Run application
- Copy chương trình ra SDCard
- Khởi động board cùng với sdcard được gắn vào
- SDCard trên board sẽ được mount vào thư mục /sdcard
- cd vào thư mục có helloworld trên sdcard
- Chạy chương trình
# ./helloworld
Hello world !
Cách copy lên sdcard tỏ ra hơi mất công, nên cách tốt nhất hay được dùng khi develop chương trình là dùng mount NFS đã được đề cập ở bài trước.
Tag :
FriendlyARM