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.

相关推荐
_F_y6 小时前
MySQL用C/C++连接
c语言·c++·mysql
BackCatK Chen7 小时前
C语言学习栏目目录
c语言·保姆级教程·c语言入门·c语言学习栏目目录
微露清风7 小时前
系统性学习Linux-第二讲-基础开发工具
linux·运维·学习
不会代码的小猴7 小时前
Linux环境编程第六天笔记--system-V IPC
linux·笔记
阳光九叶草LXGZXJ8 小时前
达梦数据库-学习-48-DmDrs控制台命令(同步之Manager、CPT模块)
linux·运维·数据库·sql·学习
诸神缄默不语8 小时前
Linux命令行教程
linux
极客数模8 小时前
【2026美赛赛题初步翻译F题】2026_ICM_Problem_F
大数据·c语言·python·数学建模·matlab
i建模10 小时前
如何在Arch Linux中重设忘记的root密码
linux·运维·服务器
kida_yuan11 小时前
【Linux】运维实战笔记 — 我常用的方法与命令
linux·运维·笔记
@syh.11 小时前
【linux】进程控制
linux