1. 程式人生 > >libcyaml編譯與測試

libcyaml編譯與測試

官網

我使用的版本

libcyaml-master.zip

這個庫需要依賴python 的yaml庫,所以需要先安裝yaml庫,安裝方法見下文連線

編譯原始碼

1、解壓原始碼包

[email protected]:~/cyaml$ unzip libcyaml-master.zip

[email protected]:~/cyaml$ cd libcyaml-master/

2、修改makefile檔案

由於之前的yaml庫並沒有安裝到系統目錄中,所以需要修改makefile檔案

[email protected]:~/cyaml/libcyaml-master$ vi Makefile

將一下這幾項根據自己的實際情況進行修改

PREFIX ?= /usr/local

INCLUDE = -I include

LDFLAGS += -lyaml

我的修改為

PREFIX ?= /home/rt/opt/cyaml

INCLUDE = -I include -I /home/rt/opt/yaml/include

LDFLAGS += -lyaml -L/home/rt/opt/yaml/lib


其中PREFIX 為安裝路徑,INCLUDE為標頭檔案查詢路徑, LDFLAGS包含庫引數。

3、編譯,安裝

[email protected]:~/cyaml/libcyaml-master$ make

[email protected]:~/cyaml/libcyaml-master$ make install

(如失敗可能需要自己建立cyaml/lib/pkgconfig目錄)

此時在安裝路徑下就有生成的檔案了

4、生成文件

[email protected]:~/cyaml/libcyaml-master$ make docs 

需要系統有doxygen,如果沒有就需要安裝sudo apt install doxygen

在/home/rt/cyaml/libcyaml-master/build/docs下就會有網頁版的文件可以檢視。

5、編譯例程

[email protected]

:~/cyaml/libcyaml-master$ make test

會做介面測試

 PASS: test_save_mapping_entry_sequence_ptr_mapping
  PASS: test_save_mapping_entry_sequence_ptr_string_ptr
  PASS: test_save_mapping_entry_sequence_ptr_mapping_ptr
  PASS: test_save_mapping_entry_sequence_ptr_sequence_fixed_int
  PASS: test_save_mapping_entry_sequence_ptr_sequence_fixed_ptr_int
  PASS: test_save_mapping_entry_sequence_ptr_sequence_fixed_flat_int
================================================================================
TEST: Save tests: various
================================================================================
  PASS: test_save_mapping_entry_ignored
  PASS: test_save_no_document_delimiters
  PASS: test_save_mapping_value_flow_style
  PASS: test_save_mapping_value_block_style
  PASS: test_save_sequence_config_flow_style
  PASS: test_save_sequence_config_block_style
  PASS: test_save_schema_top_level_sequence_fixed
================================================================================
PASS: 284 of 284 tests passed.
================================================================================

測試例子的可執行

執行/home/rt/cyaml/libcyaml-master/build/debug中的numerical和planner

進入/home/rt/cyaml/libcyaml-master/build/debug

[email protected]:~/cyaml/libcyaml-master$ cd build/debug/

[email protected]:~/cyaml/libcyaml-master/build/debug$ ./planner ../../examples/planner/project.yaml out.yaml

輸出

Project: Write new browser layout engine.
1. Read the HTML and CSS specs.
2. Think of name for library.
3. Create project repo.
4. Initial design of library API.
5. Plan the initial implementation
[email protected]:~/cyaml/libcyaml-master/build/debug$ cat out.yaml 
project: Write new browser layout engine.
start:
  day: 1
  year: 2018
  month: June
people:
- Stephen
- Neil
- Alex
tasks:
- name: Read the HTML and CSS specs.
  flags:
  - Important
  estimate:
    hours: 0
    days: 3
    weeks: 3
    years: 0
  depends: []
  people:
  - Stephen
  - Neil
- name: Think of name for library.
  flags: []
  estimate:
    hours: 1
    days: 0
    weeks: 0
    years: 0
  depends: []
  people: []
- name: Create project repo.
  flags: []
  estimate:
    hours: 1
    days: 0
    weeks: 0
    years: 0
  depends:
  - Think of name for library.
  people:
  - Alex
- name: Initial design of library API.
  flags:
  - Important
  - Engineering
  estimate:
    hours: 0
    days: 1
    weeks: 0
    years: 0
  depends:
  - Read the HTML and CSS specs.
  - Create project repo.
  people: []
- name: Plan the initial implementation
  flags:
  - Engineering
  - Documentation
  - Management
  estimate:
    hours: 0
    days: 6
    weeks: 0
    years: 0
  depends:
  - Initial design of library API.
  people:
  - Stephen
  - Alex

下面的例子

[email protected]:~/cyaml/libcyaml-master/build/debug$ ./numerical ../../examples/numerical/fibonacci.yaml 
Fibonacci:
  - 1
  - 1
  - 2
  - 3
  - 5
  - 8

介面都很簡單,看文件足夠了,就不講解了。