Linenoise Next Generation 是基於Linenoise(可參考以前一篇關於Linenoise的文章 【解鎖】Linenoise——C命令行處理工具)的C++實現,它小巧便攜,可稱爲GNU readline的替代品,弄夠處理Linux,Windows和MacOS和UTF-8字符的命令行處理工具,與GNU readline採用的GPL許可不一樣,Linenoise-NG採用BSD許可,能夠在任何程序中使用。
Linenoise-NG雖然以C++實現但仍然提供C的API。linux
須要支持C++11,cmake版本在2.6以上
cmake_minimum_required(VERSION 2.6) set(BASE_COMPILER_OPTIONS "-std=c++11 -Wall -Wextra")
在linux上編譯要先建立build目錄c++
mkdir build
而後進行編譯git
(cd build && cmake -DCMAKE\_BUILD\_TYPE=Release .. && make)
編譯並進行默認安裝segmentfault
(cd build && cmake -DCMAKE\_BUILD\_TYPE=Release .. && make && sudo make install)
經過設置DESTDIR
變量來指定安裝目錄windows
(cd build && make DESTDIR=/tmp install)
上面是官方的編譯說明,但我實際編譯時遇到下面的問題
Windows Terminal \[frank@LAPTOP-0OCJTGJR build\]$ make Scanning dependencies of target linenoise \[ 16%\] Building CXX object CMakeFiles/linenoise.dir/src/ConvertUTF.cpp.o \[ 33%\] Building CXX object CMakeFiles/linenoise.dir/src/linenoise.cpp.o \[ 50%\] Building CXX object CMakeFiles/linenoise.dir/src/wcwidth.cpp.o \[ 66%\] Linking CXX static library liblinenoise.a \[ 66%\] Built target linenoise Scanning dependencies of target example \[ 83%\] Building C object CMakeFiles/example.dir/tst/example.c.o /home/frank/git/linenoise-ng/tst/example.c: In function ‘main’: /home/frank/git/linenoise-ng/tst/example.c:49:7: error: ‘for’ loop initial declarations are only allowed in C99 mode for (int index = 0; ; ++index) { ^ /home/frank/git/linenoise-ng/tst/example.c:49:7: note: use option -std=c99 or -std=gnu99 to compile your code make\[2\]: \*\*\* \[CMakeFiles/example.dir/tst/example.c.o\] Error 1 make\[1\]: \*\*\* \[CMakeFiles/example.dir/all\] Error 2 make: \*\*\* \[all\] Error 2
靜態庫編譯成功liblinenoise.a
,但example.c編譯失敗,
根據報錯信息:for循環的寫法只適用於C99。這個可能和我最近一直在鼓搗升級gcc和glibc有關
,也許你不會遇到,簡單修改代碼,編譯經過。api
Windows Terminal \[frank@LAPTOP-0OCJTGJR build\]$ make Scanning dependencies of target linenoise \[ 16%\] Building CXX object CMakeFiles/linenoise.dir/src/ConvertUTF.cpp.o \[ 33%\] Building CXX object CMakeFiles/linenoise.dir/src/linenoise.cpp.o \[ 50%\] Building CXX object CMakeFiles/linenoise.dir/src/wcwidth.cpp.o \[ 66%\] Linking CXX static library liblinenoise.a \[ 66%\] Built target linenoise Scanning dependencies of target example \[ 83%\] Building C object CMakeFiles/example.dir/tst/example.c.o \[100%\] Linking CXX executable example \[100%\] Built target example \[frank@LAPTOP-0OCJTGJR build\]$
哦,對了,修改方法就是把int i定義放在for的外面。bash
api和Linenoise基本同樣,風格也同樣能夠參考上一篇【解鎖】Linenoise——C命令行處理工具中api一節的介紹。工具