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.

相关推荐
努力学习的小廉2 小时前
深入了解linux系统—— 线程池
linux·运维·服务器
不是编程家2 小时前
Linux第十五讲:Socket编程UDP
linux·运维·udp
UrSpecial3 小时前
Linux线程
linux·开发语言·c++
格林威3 小时前
Linux使用-MySQL的使用
linux·运维·人工智能·数码相机·mysql·计算机视觉·视觉检测
程序员TNT3 小时前
Shoptnt 促销计算引擎详解:策略模式与责任链的完美融合
linux·windows·策略模式
大锦终3 小时前
【Linux】进程间通信
linux·运维·服务器·c++
九皇叔叔3 小时前
【2】标识符
c语言
望获linux3 小时前
【实时Linux实战系列】规避缺页中断:mlock/hugetlb 与页面预热
java·linux·服务器·数据库·chrome·算法
成都极云科技3 小时前
独立显卡和集成显卡切换电脑卡住了怎么办?
linux·电脑·集成显卡·独立显卡