Hi3516a移植SDL+FreeType+SDL_ttf

本文详细介绍了在aarch64架构下编译FreeType、SDL及SDL_ttf的过程,并解决了编译过程中遇到的问题。通过具体的编译命令和步骤,展示了如何配置交叉编译环境并生成所需的库文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

aarch64下 


 

freeType

./configure --prefix=${PWD}/dst CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu



SDL

./configure --prefix=${PWD}/dst CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --disable-alsa --disable-pulseaudio --enable-esd=no



SDL_ttf

./configure --prefix=${PWD}/dst CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu --with-freetype-exec-prefix=/root/work/code/BaseCore/src/freetype/freetype-2.4.10/dst --with-sdl-prefix=/root/work/code/BaseCore/src/SDL/SDL-1.2.15/dst

SDL+FreeType+SDL_ttf库编译过程

freeType编译过程

  • 解压:tar -xvf freetype-2.4.10.tar.gz
  • 进入freeType目录:
//./configure CC=arm-hisiv500-linux-gcc --host=arm-hisiv500-linux

                ./configure --prefix=/root/work/code/BaseCore/src/freetype/hisi500 CC=arm-hisiv500-linux-gcc --host=arm-hisiv500-linux 

  • 1
  • make
  • make install

SDL编译过程

  • 解压:tar -xvf SDL-1.2.15.tar.gz
  • 进入SDL目录:
./configure CC=arm-hisiv500-linux-gcc --host=arm-hisiv500-linux --disable-alsa --disable-pulseaudio --enable-esd=no 
  • 1

出现问题1:

./src/audio/esd/SDL_esdaudio.c:30:17: fatal error: esd.h: 没有那个文件或目录
  • 1

解决方法1: 
加上--enable-esd=no,这个错误好像是音频相关的错误,这里直接关掉音频。 
make 
make install

SDL_ttf编译过程

  • 解压:tar xvf SDL_ttf-2.0.11.tar.gz
  • 进入SDL_ttf-2.0.11目录:
./configure CC=arm-hisiv500-linux-gcc --host=arm-hisiv500-linux
  • 1

若上述过程成功,会在/usr/local目录下生成相应文件: 
在/usr/local目录下执行tree -L 2(ps:有时间要研究下tree命令),结果如下:

.
├── bin
│   ├── freetype-config
│   └── sdl-config
├── etc
├── games
├── include
│   ├── freetype2
│   ├── ft2build.h
│   └── SDL
├── lib
│   ├── libfreetype.a
│   ├── libfreetype.la
│   ├── libfreetype.so -> libfreetype.so.6.9.0
│   ├── libfreetype.so.6 -> libfreetype.so.6.9.0
│   ├── libfreetype.so.6.9.0
│   ├── libSDL-1.2.so.0 -> libSDL-1.2.so.0.11.4
│   ├── libSDL-1.2.so.0.11.4
│   ├── libSDL.a
│   ├── libSDL.la
│   ├── libSDLmain.a
│   ├── libSDLmain.la
│   ├── libSDL.so -> libSDL-1.2.so.0.11.4
│   ├── libSDL_ttf-2.0.so.0 -> libSDL_ttf-2.0.so.0.10.1
│   ├── libSDL_ttf-2.0.so.0.10.1
│   ├── libSDL_ttf.a
│   ├── libSDL_ttf.la
│   ├── libSDL_ttf.so -> libSDL_ttf-2.0.so.0.10.1
│   ├── pkgconfig
│   ├── python2.7
│   └── python3.5
├── man -> share/man
├── sbin
├── share
│   ├── aclocal
│   ├── ca-certificates
│   ├── emacs
│   ├── fonts
│   ├── man
│   ├── sgml
│   └── xml
└── src
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 拷贝生成sdl库
mkdir -C /opt/sdl_lib
cd /opt/sdl_lib
cp /usr/local/include/ ./ -rf
cp /usr/local/lib/ ./ -rf 
  • 1
  • 2
  • 3
  • 4

测试

ps:这个程序不是我写的,感谢作者Sues

/*************************************************************************
  > File Name: test.c
  > Author: Sues
  > Mail: sumory.kaka@foxmail.com 
  > Created Time: 2017年02月28日 星期二 21时47分05秒
 ************************************************************************/

#include <stdio.h>
#include "SDL.h"
#include "SDL_ttf.h"

int main(int argc, const char *argv[])
{
    char * pstr = "hello";
    SDL_PixelFormat *fmt;
    TTF_Font *font;  
    SDL_Surface *text, *temp;  

    if (TTF_Init() < 0 ) 
    {  
        fprintf(stderr, "Couldn't initialize TTF: %s\n", SDL_GetError());  
        SDL_Quit();
    }  

    font = TTF_OpenFont("./simhei.ttf", 48); 
    if ( font == NULL ) 
    {  
        fprintf(stderr, "Couldn't load %d pt font from %s: %s\n", 18, "ptsize", SDL_GetError());  
    }  

    SDL_Color forecol = { 0xff, 0xff, 0xff, 0xff };  
    text = TTF_RenderUTF8_Solid(font, pstr, forecol);

    fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
    memset(fmt,0,sizeof(SDL_PixelFormat));
    fmt->BitsPerPixel = 16;
    fmt->BytesPerPixel = 2;
    fmt->colorkey = 0xffffffff;
    fmt->alpha = 0xff;

    temp = SDL_ConvertSurface(text,fmt,0);
    SDL_SaveBMP(temp, "save.bmp"); 

    free(fmt);
    SDL_FreeSurface(text);  
    SDL_FreeSurface(temp);
    TTF_CloseFont(font);  
    TTF_Quit();  

    return 0;
}

编译命令:

arm-hisiv500-linux-gcc test.c `sdl-config --cflags --libs` -I/opt/sdl_lib/include -I/opt/sdl_lib/include/SDL -L/opt/sdl_lib/lib -lSDL -lSDL_ttf -Wl,-rpath -o test
  • 1

在开发板上执行test,会生成save.bmp,打开后可以发现是Hello! 
注意:执行需要

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sdl_lib/lib #/opt/sdl_lib/lib目录是我存放动态库文件的地方
# 同时需要在test文件下防止simhei.ttf文件,这样才能找到字体
  • 1
  • 2

总结

参考的是如下博主的资源,感谢这位博主的分享! 
参考链接

番外

因为BMP图片不能设置透明,所以显示的图在视频帧上会导致视频的背景是黑色的,而且无法去除。这个问题我纠结了好久,最后也是在易百纳论坛找到的解决方法! 
重点在于zhuangweiye大神的回答:


s32Ret = SAMPLE_RGN_UpdateCanvas("sys_time.bmp", &stBitmap, HI_TRUE, 0x8000, &stSize, stCanvasInfo.u32Stride, stRgnAttrSet.unAttr.stOverlayEx.enPixelFmt);
  • 1
  • 2

有时间再把区域+SDL的方法显示位图这一部分搞上来,暂时还是写写编译的东西吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaopengsun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值