how to build tbox xml into the demo

I saw https://blog.csdn.net/gitblog_00889/article/details/151057353 says the tbox tool has xml reader/writer functions. so

I download the code from https://github.com/tboox/tbox/releases/tag/v1.7.7 , then unzip it.

build the xml functions into the demo as following steps:

  1. cd tbox-1.7.7 and ./configure

  2. modified tbox.config.h under build/linux/x86_64/release, add one line

    #define TB_CONFIG_MODULE_HAVE_XML 1

modified demo.c under src/demo, add one line

复制代码
#define TB_CONFIG_MODULE_HAVE_XML 1
  1. make
    it reports

    /usr/bin/ld: build/.objs/demo/linux/x86_64/release/src/demo/demo.c.o:(.rodata+0x98): undefined reference to tb_demo_xml_reader_main' /usr/bin/ld: build/.objs/demo/linux/x86_64/release/src/demo/demo.c.o:(.rodata+0xa8): undefined reference to tb_demo_xml_writer_main'
    /usr/bin/ld: build/.objs/demo/linux/x86_64/release/src/demo/demo.c.o:(.rodata+0xb8): undefined reference to `tb_demo_xml_document_main'
    collect2: error: ld returned 1 exit status
    make: *** [makefile:1417: build/linux/x86_64/release/demo] Error 1

  2. then I add following lines into makefile

    build/.objs/demo/linux/x86_64/release/src/demo/xml/document.c.o: src/demo/xml/document.c
    @echo compiling.release src/demo/xml/document.c
    @mkdir -p build/.objs/demo/linux/x86_64/release/src/demo/xml
    (VV)(cc) -c $(demo_cflags) -o build/.objs/demo/linux/x86_64/release/src/demo/xml/document.c.o src/demo/xml/document.c

    build/.objs/demo/linux/x86_64/release/src/demo/xml/reader.c.o: src/demo/xml/reader.c
    @echo compiling.release src/demo/xml/reader.c
    @mkdir -p build/.objs/demo/linux/x86_64/release/src/demo/xml
    (VV)(cc) -c $(demo_cflags) -o build/.objs/demo/linux/x86_64/release/src/demo/xml/reader.c.o src/demo/xml/reader.c

    build/.objs/demo/linux/x86_64/release/src/demo/xml/writer.c.o: src/demo/xml/writer.c
    @echo compiling.release src/demo/xml/writer.c
    @mkdir -p build/.objs/demo/linux/x86_64/release/src/demo/xml
    (VV)(cc) -c $(demo_cflags) -o build/.objs/demo/linux/x86_64/release/src/demo/xml/writer.c.o src/demo/xml/writer.c

    build/.objs/tbox/linux/x86_64/release/src/tbox/xml/node.c.o: src/tbox/xml/node.c
    @echo compiling.release src/tbox/xml/node.c
    @mkdir -p build/.objs/tbox/linux/x86_64/release/src/tbox/xml
    (VV)(cc) -c $(tbox_cflags) -o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/node.c.o src/tbox/xml/node.c

    build/.objs/tbox/linux/x86_64/release/src/tbox/xml/reader.c.o: src/tbox/xml/reader.c
    @echo compiling.release src/tbox/xml/reader.c
    @mkdir -p build/.objs/tbox/linux/x86_64/release/src/tbox/xml
    (VV)(cc) -c $(tbox_cflags) -o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/reader.c.o src/tbox/xml/reader.c

    build/.objs/tbox/linux/x86_64/release/src/tbox/xml/writer.c.o: src/tbox/xml/writer.c
    @echo compiling.release src/tbox/xml/writer.c
    @mkdir -p build/.objs/tbox/linux/x86_64/release/src/tbox/xml
    (VV)(cc) -c $(tbox_cflags) -o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/writer.c.o src/tbox/xml/writer.c

I also add strings at the end of following two positions,

复制代码
tbox: build/linux/x86_64/release/libtbox.a
build/linux/x86_64/release/libtbox.a: 
...
build/.objs/tbox/linux/x86_64/release/src/tbox/xml/node.c.o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/reader.c.o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/writer.c.o
...
build/.objs/tbox/linux/x86_64/release/src/tbox/xml/node.c.o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/reader.c.o build/.objs/tbox/linux/x86_64/release/src/tbox/xml/writer.c.o


demo: build/linux/x86_64/release/demo
build/linux/x86_64/release/demo: 
...
build/.objs/demo/linux/x86_64/release/src/demo/xml/document.c.o build/.objs/demo/linux/x86_64/release/src/demo/xml/reader.c.o build/.objs/demo/linux/x86_64/release/src/demo/xml/writer.c.o
...
build/.objs/demo/linux/x86_64/release/src/demo/xml/document.c.o build/.objs/demo/linux/x86_64/release/src/demo/xml/reader.c.o build/.objs/demo/linux/x86_64/release/src/demo/xml/writer.c.o
  1. run make again

    It build the demo and libtbox.a under /build/linux/x86_64/release .

  2. run

    build/linux/x86_64/release/demo xml_writer a.xml

it build the file a.xml.

复制代码
build/linux/x86_64/release/demo xml_reader a.xml
<?xml version = "1.0" encoding = "utf-8" ?>
<!--comments ...-->
<labels name = "hello world">


        <label_1 label = "1" id = "1">

                characters

        </label_1>


        <label_2 id = "2" bool = "true">

                characters

        </label_2>


        <label_3 label = "3" id = "3">

                characters

                <label_4 id = "-4" bool = "false"/>


                <label_5/>


        </label_3>


        <![CDATA[datas]]>
</labels>

it print the content of the file a.xml we just wrote. adding the blank lines as above,

复制代码
build/linux/x86_64/release/demo xml_document a.xml b.xml

it wrote the content of the file a.xml to b.xml, also adding the blank lines as above.

相关推荐
yuanmenghao3 分钟前
Linux 性能实战 | 第 7 篇 CPU 核心负载与调度器概念
linux·网络·性能优化·unix
qq_2975746716 分钟前
Linux 服务器 Java 开发环境搭建保姆级教程
java·linux·服务器
70asunflower42 分钟前
Emulation,Simulation,Virtualization,Imitation 的区别?
linux·docker
神梦流1 小时前
GE 引擎的内存优化终局:静态生命周期分析指导下的内存分配与复用策略
linux·运维·服务器
凡人叶枫1 小时前
C++中输入、输出和文件操作详解(Linux实战版)| 从基础到项目落地,避坑指南
linux·服务器·c语言·开发语言·c++
wdfk_prog2 小时前
[Linux]学习笔记系列 -- [drivers][input]serio
linux·笔记·学习
xuhe22 小时前
[全流程详细教程]Docker部署ClawBot, 使用GLM4.7, 接入TG Bot实现私人助理. 解决Docker Openclaw Permission Denied问题
linux·docker·ai·github·tldr
Lsir10110_2 小时前
【Linux】进程信号(下半)
linux·运维·服务器
傻乐u兔2 小时前
C语言进阶————指针3
c语言·开发语言
酉鬼女又兒2 小时前
零基础入门Linux指南:每天一个Linux命令_pwd
linux·运维·服务器