下載庫:
http://www.gnu.org/software/libmicrohttpd/
這裡有簡單的該庫介紹以及使用方法(簡略)。
下載:
$ svn checkout https://gnunet.org/svn/libmicrohttpd/
使用手冊:
http://www.gnu.org/software/libmicrohttpd/microhttpd.pdf
使用教程:
http://www.gnu.org/software/libmicrohttpd/tutorial.pdf
(使用手冊和使用教程都是講怎麼用這個庫的。使用手冊主要是API的調用、參數意義以及調用例子、各資料結構等,使用教程是使用手冊的補充,使用教程相當與大綱,使用手冊相當與細則。)
libmicrohttpd庫如果要有https/SSL/TLS的支援,需要libgcrypt和libgnutls庫:
http://www.gnupg.org/download/index.en.html#libgcrypt
ftp://ftp.gnu.org/gnu/gnutls/
我linux下,且要支援https。下載之。
----------------------------------------------
安裝依賴庫:
1.安裝libgcrypt庫:
$ ./configure
configure: error: libgpg-error is needed.
See ftp://ftp.gnupg.org/gcrypt/libgpg-error/
去ftp://ftp.gnupg.org/gcrypt/libgpg-error/下載libgpg-error, ./configure,make,sudo make install.
繼續對libgcrypt進行./configure,make,sudo make install.
2.安裝libgnutls庫:
$ ./configure
configure: error:
***
*** Libnettle 2.4 was not found. You must compile nettle with gmp support.
去ftp://ftp.lysator.liu.se/pub/security/lsh下載nettle,./configure,make,sudo make install.
繼續對libgnutls進行./configure,依然
configure: error:
***
*** Libnettle 2.4 was not found. You must compile nettle with gmp support.
查看gnutls-3.0.19/README,有這麼一句話:
The library depends on libnettle and p11-kit.
去http://p11-glue.freedesktop.org/releases/下載p11-kit,./configure,make,sudo make install.
對libgnutls進行./configure,依舊。。。日!
“You must compile nettle with gmp support”?
去http://gmplib.org/下載gmp。。。然後各種曲折,最後終於成功編好了gnutls庫,這部分步驟如下:
$ cd p11-kit-0.12/
$ ./configure
$ make
$ sudo make install
$ cd gmp-5.0.5/
$ ./configure
這裡可能會提示:
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
$ m4
程式“m4”尚未安裝。 您可以使用以下命令安裝:
sudo apt-get install m4
$ sudo apt-get install m4
$ ./configure
$ make
$ sudo make install
$ cd nettle-2.4
$ make clean #必須!
$ ./configure
$ make
$ sudo make install
$ cd gnutls-3.0.19
$ ./configure
$ make
$ sudo make install
----------------------------------------------
安裝目標libmicrohttpd庫:
例行查看README檔案,重要訊息如下:
If you are using Subversion, run "autoreconf -fi" to create configure.
再例行查看INSTALL檔案,重要訊息如下:
沒有重要訊息,這檔案是預設建立的。估計是GNU packages的INSTALL模板。
$ cd libmicrohttpd/
$ sudo apt-get install autoconf
$ sudo apt-get install libtool
$ autoreconf -fi
$ ./configure
注意,如果之前make過,這裡要make clean!再./configure,make,sudo make install之。
----------------------------------------------
libmicrohttpd的測試案例需要的庫:
libmicrohttpd源碼裡的測試案例會用到libcurl,zzuf和socat庫,乾脆把他們都裝上。
去http://curl.haxx.se/download.html下載curl庫,
去http://caca.zoy.org/wiki/zzuf下載zzur,
去http://www.dest-unreach.org/socat/download/下載socat。
編socat的時候,make時出了個插曲,需要sudo apt-get install yodl。
------------------------------------------------
再編 libmicrohttpd :
$ cd libmicrohttpd
$ make clean
$ autoreconf -fi
$ ./configure
configure: Configuration Summary:
Operating System: linux-gnu
libgcrypt: yes
libcurl (testing): yes
Target directory: /usr/local
Messages: yes
HTTP Authentic.: yes
Postproc: yes
HTTPS support: yes
configure: HTTPS subsystem configuration:
License : LGPL only
這些yes啊說明所有的依賴庫和test case的依賴庫都已安裝來
$ sudo apt-get install texinfo #這個的make需要這個
$ make
$ sudo make install
------------------------------------------------
檢驗庫安裝正確鳥:
$ cd libmicrohttpd/doc/examples
$ vi Makefile
CC=g++CFLAGS=-WallLDFLAGS+=-ldlMyIncPath=/usr/local/includeMyLibPath=/usr/local/libMyLibsName=microhttpd_I=$(addprefix -I,$(subst :, ,$(MyIncPath)))_L=$(addprefix -L,$(subst :, ,$(MyLibPath)))_l=$(addprefix -l,$(subst :, ,$(MyLibsName)))all:ifdef name$(CC) $(CFLAGS) -o $(addsuffix .exec,$(name)) $(addsuffix .c,$(name)) $(_I) $(_L) $(_l) $(LDFLAGS) else@echo "usage:make name=hellobrowser"endifclean:rm -rf *.exec
$ make name=hellobrowser
$ ./hellobrowser.exec
error while loading shared libraries: libmicrohttpd.so.10: cannot open shared object file: No such file or directory
$ sudo vi /etc/ld.so.conf
添加一行:/usr/local/lib
$ sudo ldconfig使生效
$ ./hellobrowser.exec
開啟瀏覽器輸入http://localhost:8888出現“Hello, browser!”頁面說明正確鳥~
end 4 have libmicrohttpd.