(原)linux下編譯microhttpd庫(一個c/c++的http服務端庫)


下載庫:

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=-Wall
LDFLAGS+=-ldl

MyIncPath=/usr/local/include
MyLibPath=/usr/local/lib
MyLibsName=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"
endif

clean:
	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.

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM