OpenEuler 上 TBOX 的安装使用

189 阅读1分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第7天,点击查看活动详情

本篇文章是为了确保可在 openEuler 上进行 TBOX 的安装,并测试和使用其模块。

TBOX 是什么

TBOX 是一个用 c 语言实现的跨平台开发库。

安装 TBOX

因为整个 tbox 项目都是由 xmake 这个跨平台的构建工具维护的。编译 tbox 源码,需要先安装 xmake 构建工具。

  1. 安装 xmake
#直接使用脚本安装
bash <(curl -fsSL https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh)Copy to clipboardErrorCopied
​
# 或者通过wget
bash <(wget https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/get.sh -O -)
Copy to clipboardErrorCopied
​
#运行`xmake update`,确保为最新版本。
xmake update
  1. 下载源码、编译。
git clone https://gitee.com/tboox/tbox.git
cd tbox
xmake

如果你想直接创建一个带有 tbox 的空工程模型,也可以直接执行 xmake create -t console_box dir_name 命令来快速集成和编译使用 tbox。

在 openEuler 上安装的过程中, TBOX 有几率出现编译问题。

[ydyk@localhost ~]$ cd tbox/
[ydyk@localhost tbox]$ xmake
checking for platform ... linux
checking for architecture ... x86_64
……
checking for libc_strlcpy ... no
checking for libc_wcscasestr ... no
checking for libm_sincos ... ok
checking for posix_pthread_setaffinity_np ... ok
checking for libc_setjmp ... ok
checking for posix_open ... ok
checking for libm_fmod ... ok
checking for libc_strchr ... ok
checking for libc_fwrite ... ok
checking for libc_wcscat ... ok
checking for libc_memcmp ... ok
checking for wchar ... no
……
checking for libc_wcslcpy ... no
……
generating src/tbox/tbox.config.h.in ... ok
[  0%]: ccache compiling.release src/tbox/tbox.c
[  0%]: ccache compiling.release src/tbox/hash/adler32.c
……
[  0%]: ccache compiling.release src/tbox/math/impl/math.c
error: src/tbox/hash/../prefix/type.h:100:9: error: unknown type name ‘__WCHAR_TYPE__’
  100 | typedef __WCHAR_TYPE__              tb_wchar_t;
      |         ^~~~~~~~~~~~~~
src/tbox/hash/../prefix/type.h:157:9: error: unknown type name ‘__tb_volatile__’
  157 | typedef __tb_volatile__  __tb_aligned__(4) tb_int32_t   tb_atomic32_t;
      |         ^~~~~~~~~~~~~~~
src/tbox/hash/../prefix/type.h:157:41: error: expected declaration specifiers or ‘...’ before numeric constant
  157 | typedef __tb_volatile__  __tb_aligned__(4) tb_int32_t   tb_atomic32_t;
      |                                         ^
src/tbox/hash/../prefix/type.h:164:9: error: unknown type name ‘__tb_volatile__’
  164 | typedef __tb_volatile__ __tb_aligned__(8) tb_int64_t    tb_atomic64_t;
      |         ^~~~~~~~~~~~~~~
src/tbox/hash/../prefix/type.h:164:40: error: expected declaration specifiers or ‘...’ before numeric constant
  164 | typedef __tb_volatile__ __tb_aligned__(8) tb_int64_t    tb_atomic64_t;
      |                                        ^
src/tbox/hash/../prefix/type.h:169:9: error: unknown type name ‘tb_atomic64_t’
  169 | typedef tb_atomic64_t                                   tb_atomic_t;
  > in src/tbox/hash/adler32.c

如果遇到以上情况,可以重新下载 tbox 进行编译,或者运行 xmake f -c 后重新编译。

  1. 运行测试
[ydyk@localhost tbox]$ xmake run demo math_random
[demo]: time: 16, average: 800, range: 600 - 1000
[demo]: time: 15, average: 149, range: 100 - 200
[demo]: time: 15, average: 201, range: -600 - 1000
[demo]: time: 16, average: -200, range: -600 - 200
[demo]: time: 16, average: -400, range: -600 - -200
[demo]: time: 15, average: 0.499821, range: 0.000000 - 1.000000
[demo]: time: 17, average: 100.094902, range: 0.000000 - 200.000000
[demo]: time: 15, average: 100.011360, range: -200.000000 - 0.000000
[demo]: time: 16, average: 199.802993, range: -200.000000 - 200.000000

简单使用

这一部分简单介绍一下 stream 模块的使用

流的初始化操作

//初始化http流
tb_stream_ref_t stream = tb_stream_init_from_url("https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP3/ISO/x86_64/openEuler-20.03-LTS-SP3-everything-debug-x86_64-dvd.iso");
//或者通过端口访问
tb_stream_ref_t stream = tb_stream_init_from_http("www.xxxx.com", 80, "/file?args=xxx",tb_false );

以上只是简单介绍了使用方法,实际实现和使用中可以根据需求进行自定义流。

参阅