嵌入式hi3516-hi3518海思平台移植nginx-1.12.2

来源:互联网 发布:淘宝哪家买iphone靠谱 编辑:程序博客网 时间:2024/05/17 03:43





参考:http://blog.csdn.net/fish43237/article/details/40515897


正文:
    先编译了linux下的nginx没有太大的问题。但是因为 nginx 对交叉编译的支持不太好。所以如果想 nginx 移植到其它环境中,会出现比较多的问题。本文 编译的是 最新的 stalble 版本,nginx-1.12.2, 目标是海思的hi3518, 编译器为arm-hisvi100nptl-linux。


pcre-8.41:下载地址 https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
nginx-1.12.2 :下载地址 http://nginx.org/en/download.html
openssl-1.0.2l :  下载地址 https://www.openssl.org/source/old/
分别解压到/home/share/opensource




1、环境设置、声明变量、执行configure
(1)cd nginx-1.12.2/
(3)nginx 编译用到的变量
 BUILD_PATH=$PWD
 INSTALL_PATH=/opt/nginx     //安装目录,可自定义
CC_PATH=/opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin/arm-hisiv100nptl-linux-gcc 
   CPP_PATH=/opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin/arm-hisiv100nptl-linux-g++
   CONFIG_DIR=/opt/nginx/conf
   LOG_DIR=/opt/nginx/log
   TEMP_DIR=/opt/nginx/tmp


(4)执行configure,生成Makefile
./configure \
--prefix=$INSTALL_PATH \
--conf-path=$CONFIG_DIR/nginx.conf \
--error-log-path=$LOG_DIR/error.log \
--pid-path=$CONFIG_DIR/nginx.pid \
--lock-path=$CONFIG_DIR/nginx.lock \
--http-log-path=$LOG_DIR/access.log \
--http-client-body-temp-path=$TEMP_DIR/body \
--http-proxy-temp-path=$TEMP_DIR/proxy \
--http-fastcgi-temp-path=$TEMP_DIR/fastcgi \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_gzip_module \
--with-http_ssl_module \
--with-pcre=/home/share/opensource/pcre-8.41 \
--with-openssl=/home/share/opensource/openssl-1.0.2l \
--with-cc=$CC_PATH  \
--with-cpp=$CPP_PATH \
--with-cc-opt="-I /opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin" \
--with-ld-opt="-L /opt/hisi-linux-nptl/arm-hisiv100-linux/target/lib" \
--with-http_ssl_module


(4)执行make 和make install




二、遇到的问题
(1)问题内容:
 + Linux 3.2.0-29-generic-pae i686
checking for C compiler ... found but is not working


./configure: error: C compiler /opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin/arm-hisiv100nptl-linux-gcc is not found


(2)原因分析:
configure首先会编译一个小测试程序,通过测试其运行结果来判断编译器是否能正常工作,由于交叉编译器所编译出的程序是无法在编译主机上运行的,故而产生此错误。
(3)解决办法:
编辑auto/cc/name文件,将21行的“exit 1”注释掉(令测试程序不会报错)。


三、遇到的问题
(1)问题内容:
autotest : 4 : not found 
autotest:Syntax error: Unterminated quoted string bytes 
./configure : error:can not detect int size
cat : /home/ubuntu/packets/nginx-1.6.2/build/autotest.c: No such file or directory
(2)原因分析:
configure通过运行测试程序来获得“int、long、longlong”等数据类型的大小,由于交叉编译器所编译出的程序无法在编译主机上运行而产生错误。
(3)解决办法:可以通过修改configure文件来手动指定各数据类型的大小,但会非常麻烦。这里,由于编译主机与目标平台均为32位系统,故可以用“gcc”替代“mips-openwrt-linux-gcc”来进行数据类型大小的测试(注意:不同的编译环境可能编译器有点不同)
编辑auto/types/sizeof文件,大概36行的位置( $CC 改为 gcc )
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
该为ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS 


四、遇到的问题
(1)问题内容:
./configure:error:can not detect int size
cat:/home/ubuntu/packets/nginx-1.6.2/build/autotest.c: No such file ordirectory
(2)原因分析:检测不到size
(3)解决办法:两个问题,一个是检测不到size。一个是找不到测试程序源代码。
先解决 size 问题,修改 auto/types/sizeof 文件,找到 ngx_size= 这一行,改为 ngx_size=4
修改完之后,再次configure,发现 autotest.c 的问题也消失了。


五、遇到的问题:
(1)问题内容:sha1 library is not found
(2)原因分析:弄不清楚
(3)解决办法:configure的时候增加参数 --with-http_ssl_module


六、遇到的问题:
(1)问题内容:./configure : error :SSL modules require the OpenSSL library.
(2)原因分析:没有说清楚openssl的源代码路径
(3)解决办法:指明openssl代码的路径。--with-openssl=DIR(DIR表示openssl源代码解压的路径)


七、遇到的问题:
(1)问题内容: make:没有什么可以做的为`default'。
(2)原因分析:没有说清楚openssl的源代码路径
(3)解决办法:
进入build目录(具体是哪个目录,需要察看Makefile,执行make)
譬如说我的 configure 生成的 Makefile 里面有一段
build:
$(MAKE) -f /home/ubuntu/packets/nginx-1.6.2/build/Makefile
$(MAKE) -f /home/ubuntu/packets/nginx-1.6.2/build/Makefile manpage
所以应该进入/home/ubuntu/packets/nginx-1.6.2/build目录,执行make


八、遇到的问题
(1)问题内容:没有规则可以创建 “/home/ubuntu/packets/nginx-1.4.7/build/src/core/nginx.o” 需要的目标 “src/core/nginx.h” 。
(2)原因分析:不知道是不是软件的 bug,指定build路径后,build路径里面的源代码是空的
(3)解决办法:把主目录的src文件夹里面的东西,拷贝到build目录(build目录请根据自己实际情况进行确定,参考上面那个问题)


九、遇到的问题
(1)问题内容:
checking whether we are cross compiling... configure: error: in `/home/share/opensource/pcre-8.41':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make[1]: *** [/home/share/opensource/pcre-8.41/Makefile] 错误 1


(2)原因分析:出错的是pcre而不是openssl。原因是编译 pcre 没有指定 `--host' 参数
(3)解决办法:
打开objs/Makefile,找到 pcre 参数设定的那几行。
1171 /home/share/opensource/pcre-8.41/Makefile:      objs/Makefile
1172         cd /home/share/opensource/pcre-8.41 \
1173         && if [ -f Makefile ]; then $(MAKE) distclean; fi \
1174         && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
1175         ./configure --disable-shared --host=arm-hisiv100nptl-linux 


在configure那里再添加一个参数 --host=arm-hisiv100nptl-linux(根据自己的编译器修改)


十、遇到的问题
(1)问题内容:
src/os/unix/ngx_errno.c: In function 'ngx_strerror':
src/os/unix/ngx_errno.c:37: error: 'NGX_SYS_NERR' undeclared (first use in this function)
src/os/unix/ngx_errno.c:37: error: (Each undeclared identifier is reported only once
src/os/unix/ngx_errno.c:37: error: for each function it appears in.)
src/os/unix/ngx_errno.c: In function 'ngx_strerror_init':
src/os/unix/ngx_errno.c:58: error: 'NGX_SYS_NERR' undeclared (first use in this function)
make[1]: *** [objs/src/os/unix/ngx_errno.o] 错误 1
(2)原因分析:
NGX_SYS_NERR未定义,NGX_SYS_NERR正常情况下应定义在objs/ngx_auto_config.h文件中,特别注意,这是一个auto性质的文件,只有在执行了./configure后,才能生成这个文件。宏NGX_SYS_NERR的意义为,在Linux系统中有132个错误编码。
(3)解决办法:
找到ngx_auto_config.h这个文件(我的ngx_auto_config.h objs目录下,不同的configure参数,这个文件的位置可能不一样)


在文件中添加如下三行:
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif
然后,继续执行make。


十一、遇到的问题
(1)问题内容:
./dftables pcre_chartables.c
/bin/bash:./dftables:无法执行二进制文件
(2)原因分析:dftables需要在编译的时候运行,而交叉编译的程序是不能运行的,要用系统的gcc来编译才能运行
(3)解决办法:用x86的gcc来单独编译dftables(我的是ubuntu自带的gcc)。
进入pcre代码所在的目录,并且执行
gcc -Wall -O2 -DCROSS_COMPILE dftables.c -o dftables
执行完之后,返回刚才的目录,执行 make 继续编译


十二、遇到的问题
(1)问题内容:
/opt/hisi-linux-nptl/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1/../../../../arm-hisiv100-linux-uclibcgnueabi/bin/ld: /home/share/opensource/openssl-1.0.2l/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)
/opt/hisi-linux-nptl/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1/../../../../arm-hisiv100-linux-uclibcgnueabi/bin/ld: /home/share/opensource/openssl-1.0.2l/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)
/opt/hisi-linux-nptl/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1/../../../../arm-hisiv100-linux-uclibcgnueabi/bin/ld: /home/share/opensource/openssl-1.0.2l/.openssl/lib/libssl.a(s23_meth.o): Relocations in generic ELF (EM: 3)
/home/share/opensource/openssl-1.0.2l/.openssl/lib/libssl.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] 错误 1


(2)原因分析:原因是编译在nginx执行configure的时候,交叉编译参数没有很好的传到openssl。
(3)解决办法:
打开主目录的Makefile,搜索到包含 /home/share/opensource/openssl-1.0.2l/.openssl/include/openssl/ssl.h:的那一行(可能不同的版本会有一点点区别,搜索openssl,找到最接近那行)
然后,在config的参数那里增加一个,指明交叉编译器所在的路径(请根据实际情况设定)
 --cross-compile-prefix=/opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin/arm-hisiv100nptl-linux- \


(需要注意的是,最后那里的横杠不能少,如果编译器是arm-hisiv100nptl-linux-gcc那就是arm-hisiv100nptl-linux-,如果是arm-linux-gcc就是arm-linux-)
修改完makefile之后,会导致make把所有东西都构建一遍,所以之前已经解决了的那几个问题可能会重新出现,需要再解决一回。


十三、遇到的问题
(1)问题内容:
x86cpuid.s: Assembler messages:
x86cpuid.s:4: Error: unrecognized symbol type ""
x86cpuid.s:5: Error: alignment too large: 15 assumed
x86cpuid.s:8: Error: bad instruction `pushl %ebp'
x86cpuid.s:9: Error: bad instruction `pushl %ebx'
.......
(2)原因分析:原因是编译在nginx执行configure的时候,交叉编译参数没有很好的传到openssl。
(3)解决办法:找到上面那个问题添加--cross-compile-prefix的那一行,继续添加一个参数no-asm,禁用汇编代码。


十四、遇到的问题
(1)问题内容:
objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
/home/share/opensource/nginx-1.12.2/src/core/ngx_cycle.c:473: undefined reference to `ngx_shm_free'
/home/share/opensource/nginx-1.12.2/src/core/ngx_cycle.c:478: undefined reference to `ngx_shm_alloc'
/home/share/opensource/nginx-1.12.2/src/core/ngx_cycle.c:675: undefined reference to `ngx_shm_free'
objs/src/event/ngx_event.o: In function `ngx_event_module_init':
/home/share/opensource/nginx-1.12.2/src/event/ngx_event.c:506: undefined reference to `ngx_shm_alloc'
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] 错误 1


(2)原因分析:`ngx_shm_free'函数未定义
通过查看源码可以发现,`ngx_shm_free'定义在
src/os/unix/ngx_shmem.c文件中,这个函数要正常使用的话必须要求
“NGX_HAVE_MAP_ANON、NGX_HAVE_MAP_DEVZERO、NGX_HAVE_SYSVSHM”这三个宏中有一个被定义。
(3)解决办法:
修改ngx_auto_config.h ,加入这几行:
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

阅读全文
0 0
原创粉丝点击