RHEL6U6 64bit + libghttp + “Hello world”
本篇日志,将记录我在RHEL 6.6 64bit系统上配置libghttp,并通过一段C语言的代码演示如何使用该类库的过程。
开始本文前,你应该准备好:
1. 已经安装好的RHEL 6.6
2. 下载好需要的libghttp 1.0.9的介质包
关于介质包,可以百度或者谷歌找到下载链接。
或者访问以下几个站点,可以很容易的找到下载点,免去了全网搜索的时间耗损:
1. http://www.linuxfromscratch.org/blfs/view/6.2.0/gnome/libghttp.html
2. http://download.chinaunix.net/download/0006000/5842.shtml
3. http://ftp.gnome.org/pub/GNOME/sources/libghttp/1.0/
在我的环境中,我习惯把下载的软件包上传到服务器的:/software,你如果操作的话,可以不必要如此。
1 2 3 4 5 6 7 8 9 10 11 |
[root@cobbler-server software]# pwd /software [root@cobbler-server software]# ls libghttp-1.0.9.tar.gz VMwareTools-10.0.5-3228253.tar.gz vmware-tools-distrib [root@cobbler-server software]# [root@cobbler-server software]# du -sh * 144K libghttp-1.0.9.tar.gz 69M VMwareTools-10.0.5-3228253.tar.gz 214M vmware-tools-distrib [root@cobbler-server software]# [root@cobbler-server software]# |
解压安装介质:
1 2 3 4 5 6 7 8 9 |
[root@cobbler-server software]# gunzip libghttp-1.0.9.tar.gz [root@cobbler-server software]# ls libghttp-1.0.9.tar VMwareTools-10.0.5-3228253.tar.gz vmware-tools-distrib [root@cobbler-server software]# [root@cobbler-server software]# tar -xf libghttp-1.0.9.tar [root@cobbler-server software]# [root@cobbler-server software]# ls libghttp-1.0.9 libghttp-1.0.9.tar VMwareTools-10.0.5-3228253.tar.gz vmware-tools-distrib [root@cobbler-server software]# |
查看解压后,有些什么文件或数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
[root@cobbler-server software]# pwd /software [root@cobbler-server software]# [root@cobbler-server software]# ls -ltr total 71200 drwxrwxrwx 3 563 563 4096 Jan 23 2001 libghttp-1.0.9 drwxr-xr-x 9 root root 4096 Nov 11 2015 vmware-tools-distrib -r--r--r-- 1 root root 72270857 Mar 27 22:20 VMwareTools-10.0.5-3228253.tar.gz -rw-r--r-- 1 root root 624640 May 30 23:12 libghttp-1.0.9.tar [root@cobbler-server software]# [root@cobbler-server software]# du -sh * 680K libghttp-1.0.9 612K libghttp-1.0.9.tar 69M VMwareTools-10.0.5-3228253.tar.gz 214M vmware-tools-distrib [root@cobbler-server software]# [root@cobbler-server software]# cd libghttp-1.0.9 [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# ls -ltr total 668 -rw-rw-r-- 1 563 563 6 Aug 24 1998 NEWS -rw-rw-r-- 1 563 563 25265 Sep 28 1998 COPYING.LIB -rw-rw-r-- 1 563 563 1053 Sep 28 1998 http_date.h -rw-rw-r-- 1 563 563 1217 Sep 28 1998 http_global.h -rw-rw-r-- 1 563 563 2924 Nov 3 1998 http_trans.h -rw-rw-r-- 1 563 563 1031 Nov 21 1998 http_base64.h -rw-rw-r-- 1 563 563 52 Dec 4 1998 README -rw-rw-r-- 1 563 563 7764 Dec 8 1998 http_trans.c -rw-rw-r-- 1 563 563 2792 Dec 10 1998 http_base64.c -rw-rw-r-- 1 563 563 555 Dec 16 1998 TODO -rw-rw-r-- 1 563 563 1494 Mar 3 1999 http_uri.h -rw-rw-r-- 1 563 563 275 May 5 1999 AUTHORS -rw-rw-r-- 1 563 563 3492 Aug 19 1999 ghttp_constants.h -rw-rw-r-- 1 563 563 2180 Aug 21 1999 http_req.h -rwxr-xr-x 1 root root 722 Dec 12 1999 mkinstalldirs -rwxr-xr-x 1 root root 6283 Dec 12 1999 missing -rwxr-xr-x 1 root root 5598 Dec 12 1999 install-sh -rw-r--r-- 1 root root 7831 Dec 12 1999 INSTALL -rw-r--r-- 1 root root 17992 Dec 12 1999 COPYING -rw-rw-r-- 1 563 563 1379 Jun 11 2000 Makefile.am -rw-rw-r-- 1 563 563 204 Jun 11 2000 ghttpConf.sh.in -rw-rw-r-- 1 563 563 1457 Jul 12 2000 libghttp.spec.in -rw-rw-r-- 1 563 563 5678 Oct 31 2000 http_uri.c -rw-rw-r-- 1 563 563 8601 Oct 31 2000 http_date.c -rw-rw-r-- 1 563 563 1060 Dec 6 2000 configure.in -rw-rw-r-- 1 563 563 6540 Dec 6 2000 http_req.c -rw-rw-r-- 1 563 563 2240 Dec 6 2000 http_hdrs.h -rw-rw-r-- 1 563 563 10048 Dec 6 2000 http_hdrs.c -rwxr-xr-x 1 563 563 97712 Jan 6 2001 ltconfig -rwxr-xr-x 1 563 563 25243 Jan 6 2001 config.sub -rwxr-xr-x 1 563 563 33085 Jan 6 2001 config.guess -rw-r--r-- 1 563 563 110868 Jan 6 2001 ltmain.sh -rw-rw-r-- 1 563 563 18444 Jan 6 2001 aclocal.m4 -rwxrwxr-x 1 563 563 71809 Jan 6 2001 configure -rw-rw-r-- 1 563 563 2518 Jan 23 2001 http_resp.h -rw-rw-r-- 1 563 563 20610 Jan 23 2001 http_resp.c -rw-rw-r-- 1 563 563 5578 Jan 23 2001 ghttp.h -rw-rw-r-- 1 563 563 19642 Jan 23 2001 ghttp.c -rw-rw-r-- 1 563 563 31101 Jan 23 2001 ChangeLog -rw-rw-r-- 1 563 563 13208 Jan 23 2001 Makefile.in -rw-rw-r-- 1 563 563 1453 Jan 23 2001 libghttp.spec drwxrwxr-x 2 563 563 4096 Jan 23 2001 doc [root@cobbler-server libghttp-1.0.9]# |
二进制编译安装:configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@cobbler-server libghttp-1.0.9]# pwd /software/libghttp-1.0.9 [root@cobbler-server libghttp-1.0.9]# ls aclocal.m4 COPYING http_base64.c http_req.c http_uri.h Makefile.am AUTHORS COPYING.LIB http_base64.h http_req.h INSTALL Makefile.in ChangeLog doc http_date.c http_resp.c install-sh missing config.guess ghttp.c http_date.h http_resp.h libghttp.spec mkinstalldirs config.sub ghttpConf.sh.in http_global.h http_trans.c libghttp.spec.in NEWS configure ghttp_constants.h http_hdrs.c http_trans.h ltconfig README configure.in ghttp.h http_hdrs.h http_uri.c ltmain.sh TODO [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# ls -ltr | grep --color configure -rw-rw-r-- 1 563 563 1060 Dec 6 2000 configure.in -rwxrwxr-x 1 563 563 71809 Jan 6 2001 configure [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# ./configure (... 过多的输出) |
./configure,这一步可能出现各种问题,下面一一列举,并给出解决方法:
1. “no acceptable cc”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@cobbler-server libghttp-1.0.9]# ./configure creating cache ./config.cache checking for a BSD compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... missing checking for working autoconf... missing checking for working automake... missing checking for working autoheader... missing checking for working makeinfo... missing checking whether to enable maintainer-specific portions of Makefiles... no checking for gcc... no checking for cc... no configure: error: no acceptable cc found in $PATH [root@cobbler-server libghttp-1.0.9]# |
出现该问题的原因是:缺少软件包 – gcc。
解决方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
[root@cobbler-server libghttp-1.0.9]# yum list | grep --color ^gcc gcc.x86_64 4.4.7-11.el6 ISO gcc-aarch64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-alpha-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-arm-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-avr32-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-bfin-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-c++.x86_64 4.4.7-11.el6 ISO gcc-c6x-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-cris-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-frv-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-gfortran.x86_64 4.4.7-11.el6 ISO gcc-gnat.x86_64 4.4.7-11.el6 ISO gcc-h8300-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-hppa64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-ia64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-java.x86_64 4.4.7-11.el6 ISO gcc-m32r-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-m68k-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-mips64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-mn10300-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-objc.x86_64 4.4.7-11.el6 ISO gcc-objc++.x86_64 4.4.7-11.el6 ISO gcc-powerpc64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-s390x-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-sh-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-sh64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-sparc64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-tile-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-x86_64-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gcc-xtensa-linux-gnu.x86_64 4.7.2-2.aa.20121114svn.el6.1 epel gccxml.x86_64 0.9.0-0.27.20150423.git3afa8ba.el6 [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# yum install -y gcc Loaded plugins: product-id, refresh-packagekit, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.4.7-11.el6 will be installed --> Processing Dependency: cpp = 4.4.7-11.el6 for package: gcc-4.4.7-11.el6.x86_64 --> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-11.el6.x86_64 --> Running transaction check ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed --> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 --> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64 ---> Package cpp.x86_64 0:4.4.7-11.el6 will be installed --> Processing Dependency: libmpfr.so.1()(64bit) for package: cpp-4.4.7-11.el6.x86_64 --> Running transaction check ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed ---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================== Package Arch Version Repository Size ====================================================================================================== Installing: gcc x86_64 4.4.7-11.el6 ISO 10 M Installing for dependencies: cloog-ppl x86_64 0.15.7-1.2.el6 ISO 93 k cpp x86_64 4.4.7-11.el6 ISO 3.7 M mpfr x86_64 2.4.1-6.el6 ISO 156 k ppl x86_64 0.10.2-11.el6 ISO 1.3 M Transaction Summary ====================================================================================================== Install 5 Package(s) Total download size: 15 M Installed size: 33 M Downloading Packages: ------------------------------------------------------------------------------------------------------ Total 33 MB/s | 15 MB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : mpfr-2.4.1-6.el6.x86_64 1/5 Installing : cpp-4.4.7-11.el6.x86_64 2/5 Installing : ppl-0.10.2-11.el6.x86_64 3/5 Installing : cloog-ppl-0.15.7-1.2.el6.x86_64 4/5 Installing : gcc-4.4.7-11.el6.x86_64 5/5 HighAvailability/productid | 1.6 kB 00:00 ... ISO/productid | 1.6 kB 00:00 ... LoadBalancer/productid | 1.6 kB 00:00 ... ResilientStorage/productid | 1.6 kB 00:00 ... ScalableFileSystem/productid | 1.6 kB 00:00 ... Server/productid | 1.6 kB 00:00 ... Verifying : ppl-0.10.2-11.el6.x86_64 1/5 Verifying : cpp-4.4.7-11.el6.x86_64 2/5 Verifying : gcc-4.4.7-11.el6.x86_64 3/5 Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 4/5 Verifying : mpfr-2.4.1-6.el6.x86_64 5/5 Installed: gcc.x86_64 0:4.4.7-11.el6 Dependency Installed: cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-11.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6 Complete! [root@cobbler-server libghttp-1.0.9]# |
2. “ltconfig: you must specify a host type if you use `–no-verify’”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
[root@cobbler-server libghttp-1.0.9]# ./configure loading cache ./config.cache checking for a BSD compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... missing checking for working autoconf... missing checking for working automake... missing checking for working autoheader... missing checking for working makeinfo... missing checking whether to enable maintainer-specific portions of Makefiles... no checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc accepts -g... yes checking for POSIXized ISC... no checking for gcc... (cached) gcc checking whether the C compiler (gcc -g -O2 ) works... yes checking whether the C compiler (gcc -g -O2 ) is a cross-compiler... no checking whether we are using GNU C... (cached) yes checking whether gcc accepts -g... (cached) yes checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking host system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized checking build system type... Invalid configuration `x86_64-unknown-linux-gnu': machine `x86_64-unknown' not recognized checking for ranlib... ranlib checking for ld used by GCC... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes updating cache ./config.cache ltconfig: you must specify a host type if you use `--no-verify' Try `ltconfig --help' for more information. configure: error: libtool configure failed [root@cobbler-server libghttp-1.0.9]# |
该问题一般出现在64位制的Linux上,查看当前Linux的位制,可以如下操作:
1 2 3 |
[root@cobbler-server libghttp-1.0.9]# getconf LONG_BIT 64 [root@cobbler-server libghttp-1.0.9]# |
而对于上面的ltconfig的问题,可以这么解决:
1 2 |
[root@cobbler-server libghttp-1.0.9]# ./configure --host=i386 (... 过多的命令输出,... 省略。) |
如果configure这一步没有问题,你会看到这样的命令反馈:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
[root@cobbler-server libghttp-1.0.9]# ./configure --host=i386 loading cache ./config.cache checking for a BSD compatible install... (cached) /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... (cached) yes checking for working aclocal... missing checking for working autoconf... missing checking for working automake... missing checking for working autoheader... missing checking for working makeinfo... missing checking whether to enable maintainer-specific portions of Makefiles... no checking for gcc... (cached) gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... (cached) yes checking whether gcc accepts -g... (cached) yes checking for POSIXized ISC... no checking for gcc... (cached) gcc checking whether the C compiler (gcc -g -O2 ) works... yes checking whether the C compiler (gcc -g -O2 ) is a cross-compiler... no checking whether we are using GNU C... (cached) yes checking whether gcc accepts -g... (cached) yes checking how to run the C preprocessor... (cached) gcc -E checking for ANSI C header files... (cached) yes checking host system type... i386-pc-none checking build system type... i386-pc-none checking for ranlib... (cached) ranlib checking for ld used by GCC... (cached) /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... (cached) yes checking for BSD-compatible nm... (cached) /usr/bin/nm -B checking whether ln -s works... (cached) yes checking for object suffix... o checking for executable suffix... no checking for gcc option to produce PIC... -fPIC checking if gcc PIC flag -fPIC works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.lo... yes checking if gcc supports -fno-rtti -fno-exceptions ... no checking if gcc static flag -static works... none checking if the linker (/usr/bin/ld) is GNU ld... yes checking whether the linker (/usr/bin/ld) supports shared libraries... yes checking command to parse /usr/bin/nm -B output... ok checking how to hardcode library paths into programs... immediate checking for /usr/bin/ld option to reload object files... -r checking dynamic linker characteristics... no checking if libtool supports shared libraries... no checking whether to build shared libraries... no checking whether to build static libraries... yes checking for objdir... .libs creating libtool loading cache ./config.cache checking host system type... i386-pc-none creating ./config.status creating libghttp.spec creating Makefile [root@cobbler-server libghttp-1.0.9]# |
注意:checking、creating。
二进制编译安装:make
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
[root@cobbler-server libghttp-1.0.9]# make /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c ghttp.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c ghttp.c -o ghttp.o echo timestamp > ghttp.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_date.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_date.c -o http_date.o echo timestamp > http_date.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_hdrs.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_hdrs.c -o http_hdrs.o echo timestamp > http_hdrs.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_req.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_req.c -o http_req.o echo timestamp > http_req.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_resp.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_resp.c -o http_resp.o echo timestamp > http_resp.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_trans.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_trans.c -o http_trans.o echo timestamp > http_trans.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_uri.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_uri.c -o http_uri.o echo timestamp > http_uri.lo /bin/sh ./libtool --mode=compile gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_base64.c gcc -DGHTTP_MAJOR_VERSION=1 -DGHTTP_MINOR_VERSION=0 -DGHTTP_MICRO_VERSION=9 -DPACKAGE=\"libghttp\" -DVERSION=\"1.0.9\" -DSTDC_HEADERS=1 -I. -I. -g -O2 -c http_base64.c -o http_base64.o echo timestamp > http_base64.lo /bin/sh ./libtool --mode=link gcc -g -O2 -o libghttp.la -rpath /usr/local/lib -version-info 1:0:0 ghttp.lo http_date.lo http_hdrs.lo http_req.lo http_resp.lo http_trans.lo http_uri.lo http_base64.lo mkdir .libs ar cru .libs/libghttp.a ghttp.o http_date.o http_hdrs.o http_req.o http_resp.o http_trans.o http_uri.o http_base64.o ranlib .libs/libghttp.a creating libghttp.la (cd .libs && rm -f libghttp.la && ln -s ../libghttp.la libghttp.la) sed -e 's?\@GHTTP_LIBDIR\@?-L/usr/local/lib?g' \ -e 's?\@GHTTP_INCLUDEDIR\@?-I/usr/local/include?g' \ -e 's?\@GHTTP_LIBS\@?-lghttp?g' \ -e 's?\@VERSION\@?1.0.9?g' \ < ./ghttpConf.sh.in > ghttpConf.tmp \ && mv ghttpConf.tmp ghttpConf.sh [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# |
二进制编译安装:make install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[root@cobbler-server libghttp-1.0.9]# make install make[1]: Entering directory `/software/libghttp-1.0.9' /bin/sh ./mkinstalldirs /usr/local/lib /bin/sh ./libtool --mode=install /usr/bin/install -c libghttp.la /usr/local/lib/libghttp.la /usr/bin/install -c .libs/libghttp.lai /usr/local/lib/libghttp.la /usr/bin/install -c .libs/libghttp.a /usr/local/lib/libghttp.a ranlib /usr/local/lib/libghttp.a chmod 644 /usr/local/lib/libghttp.a ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- /bin/sh ./mkinstalldirs /usr/local/lib /usr/bin/install -c -m 644 ./ghttpConf.sh /usr/local/lib/ghttpConf.sh /bin/sh ./mkinstalldirs /usr/local/include /usr/bin/install -c -m 644 ghttp.h /usr/local/include/ghttp.h /usr/bin/install -c -m 644 ghttp_constants.h /usr/local/include/ghttp_constants.h make[1]: Leaving directory `/software/libghttp-1.0.9' [root@cobbler-server libghttp-1.0.9]# |
这样,二进制安装就结束了。
看看安装完后的系统状态:
1 2 3 4 5 6 7 8 |
[root@cobbler-server libghttp-1.0.9]# ls -l /usr/local/lib | grep --color libghttp -rw-r--r-- 1 root root 166714 May 30 23:54 libghttp.a -rwxr-xr-x 1 root root 605 May 30 23:54 libghttp.la [root@cobbler-server libghttp-1.0.9]# [root@cobbler-server libghttp-1.0.9]# ls -l /usr/local/include/ | grep ghttp -rw-r--r-- 1 root root 3492 May 30 23:54 ghttp_constants.h -rw-r--r-- 1 root root 5578 May 30 23:54 ghttp.h [root@cobbler-server libghttp-1.0.9]# |
用一段样例代码测试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
[root@cobbler-server script]# pwd /script [root@cobbler-server script]# [root@cobbler-server script]# ls ghttp_get.c hello hello_me http_me.c http_test.c libghttp_get.c [root@cobbler-server script]# [root@cobbler-server script]# cat libghttp_get.c #include <stdio.h> #include <string.h> #include <ghttp.h> int main(int argc, char **argv) { //printf("Hello world.\n"); char *uri = "http://d-prototype.com/sitemap.html"; ghttp_request *request = NULL; ghttp_status status; FILE * pFile; char *buf; int bytes_read; int size; pFile = fopen("sitemap.html","wb"); request = ghttp_request_new(); if(ghttp_set_uri(request, uri) == -1) return -1; if(ghttp_set_type(request, ghttp_type_get) == -1) return -1; ghttp_prepare(request); status = ghttp_process(request); if(status == ghttp_error) return -1; printf("Status code -> %d\n", ghttp_status_code(request)); buf = ghttp_get_body(request); bytes_read = ghttp_get_body_len(request); size = strlen(buf); fwrite(buf, 1, size, pFile); fclose(pFile); return 0; } [root@cobbler-server script]# [root@cobbler-server script]# gcc -o libghttp_get libghttp_get.c /usr/local/lib/libghttp.a [root@cobbler-server script]# [root@cobbler-server script]# ls -ltr total 124 -rwxr-xr-x 1 root root 6491 May 31 00:02 hello -rw-r--r-- 1 root root 612 May 31 00:10 http_me.c -rw-r--r-- 1 root root 670 May 31 00:12 http_test.c -rwxr-xr-x 1 root root 6496 May 31 00:16 hello_me -rw-r--r-- 1 root root 795 May 31 00:23 libghttp_get.c -rw-r--r-- 1 root root 978 May 31 00:33 ghttp_get.c -rwxr-xr-x 1 root root 93146 May 31 00:44 libghttp_get [root@cobbler-server script]# [root@cobbler-server script]# ./libghttp_get Status code -> 200 [root@cobbler-server script]# [root@cobbler-server script]# ls -ltr total 296 -rwxr-xr-x 1 root root 6491 May 31 00:02 hello -rw-r--r-- 1 root root 612 May 31 00:10 http_me.c -rw-r--r-- 1 root root 670 May 31 00:12 http_test.c -rwxr-xr-x 1 root root 6496 May 31 00:16 hello_me -rw-r--r-- 1 root root 795 May 31 00:23 libghttp_get.c -rw-r--r-- 1 root root 978 May 31 00:33 ghttp_get.c -rwxr-xr-x 1 root root 93146 May 31 00:44 libghttp_get -rw-r--r-- 1 root root 175084 May 31 00:44 sitemap.html [root@cobbler-server script]# [root@cobbler-server script]# |
如上所示,我的代码libghttp_get.c,会抓取我的网站的站点文件:sitemap.html。
让我们看看抓取下来的sitemap.html,是否可以正常打开?
可以看到,代码抓取的页面是没有问题的。
至此,libghttp的安装与代码演示,就暂告一段落了。
————————
Done。
谢谢!我明天会按照这个步骤装一遍。