zoukankan      html  css  js  c++  java
  • (原)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.

  • 相关阅读:
    以用户、组织结构和权限为例,论如何将基于关系型数据库的设计简化
    spring InitializingBean接口
    DelegatingFilterProxy
    组织机构权限系统的实现(工作流)
    activiti 引擎 数据库设计说明书
    modeler与activiti进行整合
    流程引擎的API和服务基础
    广东程序员在加利福尼亚
    开源 -- 机器学习相关报道
    国内一些大公司的开源项目
  • 原文地址:https://www.cnblogs.com/xiaouisme/p/2515151.html
Copyright © 2011-2022 走看看