Chinaunix首页 | 论坛 | 博客
  • 博客访问: 83511
  • 博文数量: 30
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 20
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-04 13:04
文章分类

全部博文(30)

文章存档

2017年(6)

2016年(24)

我的朋友

分类: LINUX

2016-11-04 14:50:37

原文地址:ngnix powerpc交叉编译 作者:jackywgw

0.创建nginx目录
   mkdir nginx
1.在nginx目录下下载pcre

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz 
2.在nginx目录下下载zlib
   wget

3.在nginx目录下下载nginx
wget http://nginx.org/download/nginx-1.8.0.tar.gz
4.解压pcre,zlib,nginx
5.在nginx目录下编写powerpc下的Make文件
6.在nginx目录下运行mk200

点击(此处)折叠或打开

  1. /configure --prefix=/usr/local/nginx/ \
  2.                              --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/ \
  3.                              --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module \
  4.                              --with-pcre=$(AH_CURRENT_BUILD_PATH)/$(AH_PCRE_SUBDIR) --with-zlib=$(AH_CURRENT_BUILD_PATH)/$(AH_ZLIB_SUBDIR)\
  5.                              --with-openssl=$(AH_BUILD_TREE_ROOT)/app/openssl/openssl --with-cc=powerpc-linux-gnu-gcc\
  6.                              --with-cc-opt="-I$(AH_BUILD_TREE_ROOT)/app/openssl/openssl/include \
  7.                                        -I$(AEROS_ROOT)/include/share \
  8.                                        -I$(AEROS_ROOT)/include/user \
  9.                                        -I$(AEROS_ROOT)/include/boot \
  10.                                        -I$(AH_BUILD_TREE_ROOT)/include/boot \
  11.                                        -I$(AH_BUILD_TREE_ROOT)/include/share \
  12.                                        -I$(AH_BUILD_TREE_ROOT)/include/user" ;
make
make install
7.编译过程中遇到的错误

1)
错误信息:
build_BR200/include/boot -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/share -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/user" ; fi;
checking for OS
+ Linux 2.6.32-279.el6.x86_64 x86_64
checking for C compiler ... found but is not working

/home/gwwu/codes/istanbul_5_28/app/nginx/nginx-1.8.0/configure: error: C compiler powerpc-linux-gnu-gcc is not found

make: *** [header] Error 1

分析:
由于nginx里面判断某个特征是否具备是通过编译在auto/feature里面的一段c代码并且运行编译结果,由于交叉编译的环境是powerpc-linux-gnu-gcc,但是在编译的linux主机上,无法运行powerpc-linux-gnu-gcc编译的目标文件,所以导致提示 found but is not working,并最终退出。

修改:
       将nginx-1.8.0/auto/cc/name的第10行修改为空或者no


if [ "$NGX_PLATFORM" != win32 ]; then
       7
       8     ngx_feature="C compiler"
       9     ngx_feature_name=
      10     ngx_feature_run=yes                     -----------改为空或者no                                                                                                        
      11     ngx_feature_incs=
      12     ngx_feature_path=
      13     ngx_feature_libs=
      14     ngx_feature_test=
      15     . auto/feature
      16
      17     if [ $ngx_found = no ]; then
      18         echo
      19         echo $0: error: C compiler $CC is not found
      20         echo
      21         exit 1
      22     fi
      23
      24 fi


2)
继续编译,出现如下错误:

checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ...auto/types/sizeof: line 43: objs/autotest: cannot execute binary file
  bytes

/home/gwwu/codes/istanbul_5_28/app/nginx/nginx-1.8.0/configure: error: can not detect int size
cat: objs/autotest.c: No such file or directory
make: *** [header] Error 1

错误原因:
      原因也是由于nginx里面判断某个特征是否具备是通过编译在auto/type/sizeof里面的一段c代码并且运行编译结果,由于交叉编译的环境是powerpc-linux-gnu-gcc,但是在编译的linux主机上,无法运行powerpc-linux-gnu-gcc编译的目标文件,所以导致提示 objs/autotest: cannot execute binary file,并最终退出。

修改方法:
  
修改文件nginx-1.8.0/auto/type/sizeof, 15行修改为4,注册掉17到33行  


      14
      15 ngx_size=              -------------15行修改为4,注册掉17到33行                                                                                                                            
      16
      17 cat << END > $NGX_AUTOTEST.c
      18
      19 #include <sys/types.h>
      20 #include <sys/time.h>
      21 $NGX_INCLUDE_UNISTD_H
      22 #include <signal.h>
      23 #include <stdio.h>
      24 #include <sys/resource.h>
      25 $NGX_INCLUDE_INTTYPES_H
      26 $NGX_INCLUDE_AUTO_CONFIG_H
      27
      28 int main() {
      29     printf("%d", (int) sizeof($ngx_type));
      30     return 0;
      31 }
      32
      33 END


3)继续编译,出现如下错误:
checking for OpenSSL library ... not found

/home/gwwu/codes/istanbul_5_28/app/nginx/nginx-1.8.0/configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

make: *** [header] Error 1




错误原因:
      由于在nginx-1.8.0/auto/lib/openssl/conf的65行里面有个判断$OPENSSL != YES,由于没有指定--with-openssl=<path>,所以会导致退出。

autoest.c
#include <sys/types.h>
#include <unistd.h>
#include <openssl/ssl.h>

int main() {
     SSL_library_init();
     return 0;
}



powerpc-linux-gnu-gcc -I/home/gwwu/codes/istanbul_5_28/build_BR200/app/openssl/openssl/include -I/home/gwwu/codes/istanbul_5_28/include/share -I/home/gwwu/codes/istanbul_5_28/include/user -I/home/gwwu/codes/istanbul_5_28/include/boot -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/boot -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/share -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/user -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -lssl -lcrypto
编译失败,由于没有编译主机上没有这两个库文件

解决方法:
      如果环境中没有openssl库的,需要用--with-openssl选项指定。 
      但在我们的环境中,是有openssl库的,所以不需要指定--with-openssl,但是为了解决这个退出错误,注释掉56行,增加57 行ngx_found=yes
      



      45     if [ "$NGX_PLATFORM" != win32 ]; then
      46
      47         OPENSSL=NO
      48
      49         ngx_feature="OpenSSL library"
      50         ngx_feature_name="NGX_OPENSSL"
      51         ngx_feature_run=no
      52         ngx_feature_incs="#include <openssl/ssl.h>"
      53         ngx_feature_path=
      54         ngx_feature_libs="-lssl -lcrypto"
      55         ngx_feature_test="SSL_library_init()"
      56         . auto/feature     ----------注释掉此行                                                                                                                          
      57         增加ngx_found=yes
      58         if [ $ngx_found = yes ]; then
      59             have=NGX_SSL . auto/have
      60             CORE_LIBS="$CORE_LIBS $ngx_feature_libs $NGX_LIBDL"
      61             OPENSSL=YES
      62         fi
      63     fi


4)继续编译,出现错误:


make[2]: Entering directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
cd ../pcre2-10.10 \
        && if [ -f Makefile ]; then make distclean; fi \
        && CC="powerpc-linux-gnu-gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking for style of include used by make... GNU
checking for gcc... powerpc-linux-gnu-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/pcre2-10.10':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[2]: *** [../pcre2-10.10/Makefile] Error 1
make[2]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make: *** [header] Error 2


错误原因:
     pcre交叉编译的时候必须指定--host

修改:
    nginx/nginx-1.8.0/auto/lib/pcre/make里面56行,增加--host=x86_64-unknown-linux-gnu
   51 
      52 $PCRE/Makefile: $NGX_MAKEFILE
      53     cd $PCRE \\
      54     && if [ -f Makefile ]; then \$(MAKE) distclean; fi \\
      55     && CC="\$(CC)" CFLAGS="$PCRE_OPT" \\
      56     ./configure --host=linux_x86_64 --disable-shared $PCRE_CONF_OPT         --------增加--host=x86_64-unknown-linux-gnu
      57
      58 $PCRE/.libs/libpcre.a:  $PCRE/Makefile
      59     cd $PCRE \\
      60     && \$(MAKE) libpcre.la
      61
      62 END            


5)

powerpc-linux-gnu-gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I/home/gwwu/codes/istanbul_5_28/build_BR200/app/openssl/openssl/include -I/home/gwwu/codes/istanbul_5_28/include/share -I/home/gwwu/codes/istanbul_5_28/include/user -I/home/gwwu/codes/istanbul_5_28/include/boot -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/boot -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/share -I/home/gwwu/codes/istanbul_5_28/build_BR200/include/user -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/pcre2-10.10 -I /home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/zlib-1.2.8 -I objs \
                -o objs/src/core/nginx.o \
                src/core/nginx.c
In file included from src/core/ngx_core.h:70:0,
                 from src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: fatal error: pcre.h: No such file or directory
compilation terminated.
make[2]: *** [objs/src/core/nginx.o] Error 1
make[2]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make: *** [header] Error 2



解决方法:







5)错误

        objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_least_conn_module.o \
        objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
        objs/ngx_modules.o \
        -lssl -lcrypto -L/home/gwwu/codes/istanbul_5_28/build_BR200/app/openssl/openssl/openssl/ -ldl /home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/zlib-1.2.8/libz.a
/eng/crosstool/fsl-cs-toolchain-2010.09/bin/../lib/gcc/powerpc-linux-gnu/4.5.1/../../../../powerpc-linux-gnu/bin/ld: cannot find -lssl
/eng/crosstool/fsl-cs-toolchain-2010.09/bin/../lib/gcc/powerpc-linux-gnu/4.5.1/../../../../powerpc-linux-gnu/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make[2]: *** [objs/nginx] Error 1
make[2]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/gwwu/codes/istanbul_5_28/build_BR200/app/nginx/nginx-1.8.0'
make: *** [header] Error 2


原因: 找不到ssl crypto的路径
解决方法:
nginx/nginx-1.8.0/auto/lib/openssl/conf添加 -L$OPENSSL/    

26
      27         *)
      28             have=NGX_OPENSSL . auto/have
      29             have=NGX_SSL . auto/have
      30
      31             CORE_INCS="$CORE_INCS $OPENSSL/include"
      32             CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
      33             #CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
      34             #CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
      35             CORE_LIBS="$CORE_LIBS -lssl -lcrypto -L$OPENSSL/"                      添加    -L$OPENSSL                                                                             
      36             CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
      37
      38             if [ "$NGX_PLATFORM" = win32 ]; then
      39                 CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
      40             fi
      41         ;;
      42     esac
阅读(2559) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~