HISIV3519交叉编译nginx服务器

最近需要在海思板子上编译nginx, 超级难编译, 特此记录:
我的测试服务器ubuntu 64位机, 但是海思的环境是32位,安装完成后没有显示报错,但是运行的时候就显示No such file or directory , 所以需要64位机支持32位 操作如下:
pt-get update
sudo apt install lib32z1-dev
apt-get install lib32z1 lib32ncurses5
apt-get install lib32stdc++6
apt-get install gcc-multilib g+±multilib
之后就可以使用该编译器了

海思的编译器安装完之后有两个,一个是arm-hisiv500 一个是arm-hisiv600, 一直不清楚是怎么使用, 有什么区别, 后来才知道, arm-hisiv500 对应 的是他们的liteos系统, arm-hisiv600对应的是linux系统, 因为板子预装的是linux,所以我使用的是arm-hisiv600。

首先, nginx需要依赖, 所以三个依赖需要先下载下来
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget http://distfiles.macports.org/openssl/openssl-1.0.2o.tar.gz
之后分别解压, 这里就不详述了。

进入nginx 执行
./configure --with-cc=arm-hisiv600-linux-gcc --with-cpp=arm-hisiv600-linux-g++ --with-http_ssl_module --with-pcre=/home/work/c8/pcre-8.40 --with-openssl=/home/work/c8/openssl-1.0.2o --without-http_gzip_module --without-http_upstream_zone_module
注意:
–with-pcre --with-openssl 后面的是之前下载的依赖解压后的地址

./configure: error: C compiler arm-hisiv600-linux-gcc is not found
解决方法:
在auto/cc/name文件里
1)ngx_feature_run=yes改成no
2)将exit=1注释掉
if [ “$NGX_PLATFORM” != win32 ]; then

    ngx_feature="C compiler"ngx_feature_name=ngx_feature_run=nongx_feature_incs=ngx_feature_path=ngx_feature_libs=ngx_feature_test=. auto/featureif [ $ngx_found = no ]; thenechoecho $0: error: C compiler $CC is not foundecho***#exit 1***fifi

空行夹的地方就是要更改的

./configure: error: can not detect int size

解决:
在auto/type/sizeof文件里
将ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
改成
ngx_test=“gcc $CC_TEST_FLAGS $CC_AUX_FLAGS
-o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs”

configure: error: in `/home/work/c8/pcre-8.40’:
configure: error: C compiler cannot create executables

解决:
在auto/options 文件里

PCRE_CONF_OPT=
改成
PCRE_CONF_OPT=–host=arm-hisiv600-linux

openssl编译出错

auto/lib/openssl/make 里
$OPENSSL/.openssl/include/openssl/ssl.h: $NGX_MAKEFILE
cd $OPENSSL \
&& if [ -f Makefile ]; then $(MAKE) clean; fi \
&& ./Configure --prefix=$ngx_prefix no-shared no-asm linux-generic32 $OPENSSL_OPT \
&& $(MAKE) CC="/opt/hisi-linux/x86-arm/arm-hisiv600-linux/bin/arm-hisiv600-linux-gnueabi-gcc" AR="/opt/hisi-linux/x86-arm/arm-hisiv600-linux/bin/arm-hisiv600-linux-gnueabi-ar r" RANLIB="/opt/hisi-linux/x86-arm/arm-hisiv600-linux/bin/arm-hisiv600-linux-gnueabi-ranlib" \

&& $(MAKE) install_sw LIBDIR=lib

END
粗体和倾斜的地方就是更改的

recipe for target ‘objs/src/core/ngx_string.o’ failed
解决 找到对应的Maakefile文件,将gcc参数中的-Werror去掉。
即 在objs/Makefile里将
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
改成
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g

GX_SYS_NERR?.undeclared (first use in this function)
解决
找到ngx_auto_config.h这个文件(我的ngx_auto_config.h在objs目录,不同的configure参数,这个文件的位置可能不一样)
在文件最下面加上
#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR 132
#endif

GX_SYS_NERR?.undeclared (first use in this function)
原因:
ngx_shm_free函数未定义
通过查看源码可以发现,`ngx_shm_free’定义在
src/os/unix/ngx_shmem.c文件中,这个函数要正常使用的话必须要求
“NGX_HAVE_MAP_ANON、NGX_HAVE_MAP_DEVZERO、NGX_HAVE_SYSVSHM”这三个宏中有一个被定义。
解决 在ngx_auto_config.h最后
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

最终将nginx在海思的交叉编译环境下成功编译

arm-hisiv300-linux-gcc-ar:cannot find plugin liblto_plugin.so由于用户使用的交叉编译的工具链是32位,而Ubuntu16.04系统不支持32位的。
) 安装sudo apt install lib32z1-dev
2) 将配置文件config.hisiev200.demo中的OVERRIDE_AR = arm-hisiv300-linux-gcc-ar 改成OVERRIDE_AR = arm-hisiv300-linux-ar。
将/usr/lib32里的libz.so 用file libz.so查看是否是32位的, 再软连接到arm-hisiv500的安装目录里的lib里,就解决找不到libz.so的问题

非常感谢:
nginx 交叉编译
https://www.itmangoto.cn/2017/11/28/nginx-cross-compile/
交叉编译Hi3536上面使用的nginx
https://blog.csdn.net/vc66vcc/article/details/83273252
openssl交叉编译问题
https://blog.csdn.net/ty3219/article/details/77717478
arm-hisiv600-linux-gcc 编译出现提示:No such file or directory
https://blog.csdn.net/qq_20574421/article/details/80707925


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部