nginx移植到arm-linux

bbenben08 2019-07-23 10:37:46 100 已收藏
展開
這裏記錄一下所遇到的問題。

下載pcre,openssl,nginx源碼解壓到同級目錄。

在此先列下我使用各源碼的版本,以免在目標板運行時還是有問題

nginx-1.4.7(可能是我的芯片爲32位A9 處理器,開始時用了nginx-1.8版本,按照下面的流程編譯通過,但運行有問題,後來改爲nginx-1.4.7就可以正常運行了)
openssl-1.0.1s
pcre-8.39
zlib-1.2.11

配置環境變量:
export INSTALL_PATH=/usr/local/nginx //安裝路徑會寫入nginx可執行程序
export CC_PATH=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc
export CPP_PATH=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-g++

配置configure:

 ./configure --prefix=$INSTALL_PATH  \			
 --with-http_ssl_module \						
 --with-pcre=/home/pcre-8.36 \
 --with-zlib=/home/zlib-1.2.7 \
 --with-openssl=/home/openssl-1.0.2s \
 --with-cc=$CC_PATH \
 --with-cpp=$CPP_PATH
 --add-module=/home/nginx-rtmp-module-master

如需要加上nginx-rtmp-module 則如上加上此模塊源碼一起編譯即可

編譯:

make;make install

遇到的問題
這裏補上漏掉的問題:

configure錯誤:
1

checking for C compiler ... found but is not working

./configure: error: C compiler arm-hisiv400-linux-gcc is not found

vi auto/cc/name ,找到

if [ $ngx_found = no ]; then
        echo
        echo $0: error: C compiler $CC is not found
        echo
        exit 1
    fi

configure首先會編譯一個小測試程序,通過測試其運行結果來判斷編譯器是否能正常工作,由於交叉編譯器所編譯出的程序是無法在編譯主機上運行的,故而產生此錯誤。exit 1 註釋掉。

2

autotest:Syntax error: Unterminated quoted string bytes 
./configure : error:can not detect int size

出現這個錯誤是因爲使用交叉編譯器直接測試在host上是運行不了,因此把 $CC 改爲 gcc

vi auto/types/sizeof ,
ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS
改爲
ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS

ngx_size=$NGX_AUTOTEST 修改爲 ngx_size=4

make錯誤:
3
src/core/ngx_rwlock.c:125:2: error: #error ngx_atomic_cmp_set() is not defined!
這個錯誤需要將 configure時 加入–without-http_upstream_zone_module參數。

1
在這裏插入圖片描述
pcre沒有指定host。在nginx/objs/Makefile 修改

/home/pcre-8.36/Makefile:       objs/Makefile
        cd /home/pcre-8.36 \
        && if [ -f Makefile ]; then $(MAKE) distclean; fi \        
        && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
        ./configure --disable-shared

最後一行增加 --host=aarch64-linux-gnu。

2
在這裏插入圖片描述
看提示是在unix系統openssl需要使用config而不是Configure。修改nginx/objs/Makefile

/home/openssl-1.0.2s/.openssl/include/openssl/ssl.h:    objs/Makefile
        cd /home/openssl-1.0.2s \
        && if [ -f Makefile ]; then $(MAKE) clean; fi \
        && ./Configure --prefix=/home/openssl-1.0.2s/.openssl no-shared no-threads --cross-compile-prefix=/var/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu- \
        && $(MAKE) \
        && $(MAKE) install_sw LIBDIR=lib

將Configure改爲config。(此處可能有的版本已經修改,而且自動編譯成功,但會使用了x86 的gcc 編譯,因此還是需要按照上面寫的修改,並且加上no-asm ,下面有提到)

3
在這裏插入圖片描述
-m64 是64位操作系統,但是不知道爲什麼我的編譯器識別不了,所以只能到openssl文件夾單獨編譯openssl。需要刪除openssl的Makefile中所有 -m64 的地方,有兩處。SHARED_LDFLAGS=-m64這裏整行刪除。

4
在這裏插入圖片描述
這個需要修改nginx/objs/Makefile , 第2個問題中config行增加 no-asm ,禁用匯編。重新make,再到openssl文件夾修改Makefile後make;make install,回到nginx文件夾重新make

5
在這裏插入圖片描述
需要修改 objs/ngx_auto_config.h,增加

#ifndef NGX_SYS_NERR
#define NGX_SYS_NERR  132
#endif

在這裏插入圖片描述
這個問題需要修改相同位置

#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif

make成功後make install 安裝到設置的安裝目錄。

另外,我所使用的版本的nginx 編譯過程中還遇到如下問題

src/core/ngx_string.c: In function ‘ngx_atoi’:
src/core/ngx_string.c:910:5: error: overflow in implicit constant conversion [-Werror=overflow]
src/core/ngx_string.c: In function ‘ngx_atofp’:
src/core/ngx_string.c:941:5: error: overflow in implicit constant conversion [-Werror=overflow]

最後在nginx/obj/Makefile 中把 -Werror 選項去掉,則可以編譯通過

參考文章:
https://blog.csdn.net/bbenben08/article/details/96964069
https://blog.csdn.net/fish43237/article/details/40515897
https://www.jianshu.com/p/5d9b60f7b262

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章