lighttpd及pcre的交叉编译

本文档介绍了在Ubuntu 12.04环境下,如何使用mips-openwrt-linux交叉编译工具链,对lighttpd和pcre进行交叉编译,并详细阐述了编译过程中的配置步骤、库文件导入以及环境变量设置,旨在在OpenWrt系统上部署lighttpd服务器。

lighttpd及pcre的交叉编译(不成熟)

A.环境说明

  • 编译环境
    ubuntu12.04
    i686-pc-linux
  • 运行环境
    openwrt
  • 交叉编译工具
    mips-openwrt-linux

B.交叉编译思路

  • lighttpd与相关依赖库的安装 基础下进行本次交叉编译
  • 通过config脚本配置编译环境中的编译工具为交叉编译工具
  • 安装目录设置为最终运行目录,使得移植之后能够正确匹配
  • 将需要的环境配置在运行设备上

C.编译pcre

1.配置脚本(设置编译工具等)

vim configure-opw.sh

#! /bin/sh
CXX=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++ CC=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc AR=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ar LD=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ld RANLIB=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ranlib STRIP=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-strip ./configure  --prefix=/usr/pcre --host=mips-openwrt-linux --build=i686-pc-linux --enable-utf8 --enable-unicode-properties

将脚本复制到安装文件路径后,进行配置
./configure-opw.sh
注:
必须指定g++编译器,因为在本文件编译中需要通过CPP编译相关动态库,并且在之后会使用,若不指定,会出现如下错误:

  CXX      libpcrecpp_la-pcrecpp.lo
  CXX      libpcrecpp_la-pcre_scanner.lo
  CXX      libpcrecpp_la-pcre_stringpiece.lo
  CXXLD    libpcrecpp.la
./.libs/libpcre.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
2.编译安装

make && make install
提示:
可以在make编译完后可以执行make check进行测试

3.将库文件导入cache(运行环境中的)
  • 方法1:在/etc/ld.so.conf/中加入:
    /usr/local/lib/pcre,然后运行ldconfig
  • 方法2:在/etc/ld.so.conf.d/下新生成一个文件(或在其中的文件中加入同样内容),文件内容为:
    /usr/local/lib/pcre,然后运行ldconfig
4.将路径导入环境变量(运行环境的)

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$/usr/local/lib/pcre
export LD_LIBRARY_PATH
C_INCLUDE_PATH=/usr/include/libxml2:/usr/local/include/pcre
export C_INCLUDE_PATH

D.编译lighttpd

1.配置脚本(设置编译工具等)

vim configure-opw.sh

#! /bin/sh
CC=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-gcc AR=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ar LD=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ld RANLIB=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-ranlib STRIP=/home/jeff/extfs/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-strip ./configure --prefix=/tmp/webserver/lighttpd-1.4.42-opw --host=mips-openwrt-linux --build=i686-pc-linux --disable-FEATURE --enable-shared --disable-static --disable-lfs --disable-ipv6 --without-PACKAGE --without-valgrind --without-openssl --without-kerberos5 --without-pcre --without-zlib --without-bzip2

将脚本复制到安装文件路径后,进行配置
./configure-opw.sh

2.编译安装

make && make install

3.文件结构设置与配置服务器

根据需要进行服务器功能模块裁剪

5.服务器的启动和关闭
  1. 设置执行文件权限
    chmod 777 [服务器路径]/sbin -R
  2. 启动服务器
    [服务器路径]/sbin/lighttpd -f [服务器路径]/config/lighttpd.conf
  3. 访问服务器
    在浏览器中输入ip:port,访问服务器主页
    主页路径在/webpages
  4. 关闭服务器
    killall lighttpd
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值