Tensorflow ARM交叉編譯錯誤集錦


版權聲明:本文為博主(Jimchen)原創文章,未經博主允許不得轉載。

ttps://www.cnblogs.com/jimchen1218/p/11611975.html

前言:

       Tensorflow交叉編譯的過程是一個心塞的過程,其中會出現各種各樣的錯誤,個中滋味,只有經歷過的人才能體會。

       特意記錄下所有碰到的問題,一來作為這段時間的一個小結,二來可以給他人提供些幫助。

       先上一張圖,主要是針對各軟件包之間的版本對應性:

       

   實測發現,當前Tensorflow版本為1.10.0,Bazel版本只能在0.18.1~0.19.2之間

正文:

       現將已知問題列表如下,如碰到相同現象,可依此方法解決:

              問題1:

                     錯誤現象:

                            編譯過程中,提示exp("/home/jim/tf2arm/sysroots/x86_64-linux/arm-poky-linux-gnueabi-gcc") :no such file or directory

                     原因分析:

                            我在該目錄下可以該目錄,但是打開shell運行時,提示卻一樣:no such file or directory。(這個交叉編譯SDK是從別人電腦(UBUNTU系統版本14.04)上拷貝過來了,在他的電腦上可以正常執行),原因可能是由於系統與平台的差異性,導致在一台電腦上可以正常執行,在另一台電腦上卻無法執行。

                           百度查了各種方法:

                                  1) chmod 777 -R sysroots  添加可執行權限,不行

                                  2) sudo apt-get install lsb-core  添加對32位系統的兼容支持,不行

                                  3) sudo apt-get install ia32-libs   添加對32位系統的兼容支持,不行

                    解決方法:

                           用別人生成的SDK不行,那個自己編譯一個,方法可參考如下鏈接:手動編譯用於i.MX6系列的交叉編譯SDK

             問題2:

                    錯誤現象:

                           拷貝新生成的兩個可執行包到相應目錄:

                                        opt/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poly-linux-gnueabi

                                        opt/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc

                                再次編譯bash build_arm_poky.sh

                                報錯:error:target CPU does not support ARM mode

                    原因分析:

                           查看目標芯片參數:Cortex-M4對應ARMv7E-M,也就是-march=armv7-a  ,-mtune=cortex-a9

                           如果使用--mcpu=cortex-m3選項時,需要與-mthumb選項搭配。未解決!

                           通過報錯時的提示信息,發現:環境變量里有兩條記錄:-march=armv7-a和-march=armv7

                    解決方法:

                           執行腳本 :./configure 

                                              其它的選項都選No,-march選項使用armv7-a即可。

              問題3:

                     錯誤現象:

                             BUILD:tensorflow/WORKSPACE:3:1:name 'http_archive' is not defined

                     原因分析:

                            懷疑是包不兼容導致,當前bazel 0.25.2,tensorflow 1.10

                     解決方法:

                            當前tensorflow  1.10最高只能支持Bazel0.19.2,所以,降Bazel版本到0.18.1

             問題4:     

                    問題現象:

                           arm-poky-linux-gnueabi/usr/include/gnu/stubs.h:7:29:fatal error: gnu/stubs-soft.h :No such file or directory

                           compilation terminated

                    原因分析:

                           在編譯生成的包中未查找到該文件,但找到一個類似文件:stubs_hard.h,查看該文件內容,只是些宏定義。

                    解決方法:

                           直接復制文件stubs-hard.h,更名為為stubs-soft.h

      根本原因:

        在交叉編譯包的CROSSTOOL文件中,缺少了兩句話:

                                   compiler_flag:"-mfloat-abi=hard"

                                   compiler_flat:"-mfpu=vfpv3"

             問題5:

                     問題現象:

                            extern/asm/nasm/error.c,找不到error.h

                     原因分析:

                            源代碼查找error.h, 位於extern/asm/include,應該是編譯路徑包含不對導致。

                     解決方法:

                            1、 ll  ~/.cache/bazel       列出bazel_jim(當前主目錄)

                            2、 ll  ~/.cache/bazel/bazel_jim  列出各文件夾,其中包含自動生成的隨機文件夾,如果包含多個,可通過時間來判斷。找到最新的即可。

                            3、本文中隨機文件夾為:7924169126bef9c95805dc831e19e9c3,進入該文件夾下extern/nasm/:

                                     直接復制到當前文件:cp include/error.h .

 

               問題6:

                      問題現象1:

                              /home/jim/.cache/bazel/_bazel_jim/76ef6e7a149f324cd1b97025fe5e3e28/external/protobuf_archive/BUILD:645:1:undeclared inclusion(s) in rule '''@protobuf_archive??:python/google/protobuf/internal/_api_implementation.so’:

                              this rule is missing dependency declarations for the following files included by 'external/protobuf_archive/python/google/protobuf/internal/api_implementation.cc':

                                   'usr/include/python2.7/Python.h'

                                    ...

                                   'usr/include/python2.7/pyfpe.h'

                      原因分析:

                              編譯當前文件時,找不到支持該文件編譯的相應頭文件;

                      解決方法:

                             在CROSSTOOL中添加

                                     1. cxx_builtin_include_directory:"usr/include/python2.7"

                      問題現象2:

                              /home/lyra/.cache/bazel/_bazel_lyra/76ef6e7a149f324cd1b97025fe5e3e28/external/com_google_absl/absl/base/BUILD.bazel:115:1: undeclared inclusion(s) in rule '@com_google_absl//absl/base:base':
this rule is missing dependency declarations for the following files included by 'external/com_google_absl/absl/base/internal/cycleclock.cc':
  '/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h'
  '/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed/limits.h'

                      解決方法:

                             add path in  arm_compiler/CROSSTOOL

                            cxx_builtin_include_directory:"usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h"

                            cxx_builtin_include_directory:"usr/lib/gcc/x86_64-linux-gnu/5/include_fixed/limits.h"

                問題7:

                       問題現象:

                              tensorflow/python/lib/core/py_func.cc:355:39 :error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

                       解決方法:

                              根據錯誤提示文件,找到對應錯誤處,在接口返回值處添加(char *)

                              此處問題較多,有7,8處,需修改多次。

                問題8:

                       問題現象:

                               external/gif_archive/lib/egif_lib.c:62:6:error:'S_IREAD' undeclared(first use in this function)

                               external/gif_archive/lib/egif_lib.c:62:16:error:'S_IWRITE' undeclared(first use in this function)

                        原因分析:

                               錯誤原因可能是沒有編譯Android,因為在external/gif_archive下BUILD.bazel里有定義

                        解決方法:

                               方法1:

                                      修改S_IREAD為S_IRUSR

                                      修改S_IWRITE為S_IWUSR

                               方法2:

                                      在gif_lib.h中定義

                                              #define S_IREAD S_IRUSR

                                              #define S_IWRITE S_IWUSR

                問題9:

                        現象描述:

                               external/png_archive/pngpriv.h:911:4 :error:#error ZLIB_VERNUM!= PNG_ZLIB_VERNUM " -I (include path) error:see the notes in pngpriv.h

                               #error ZLIB_VERNUM != PNG_ZLIB_VERNUM 

                         原因分析:

                                 Zlib庫與libpng版本號不一致   

                                 查看Zlib版本:   

                                          find /usr/ -name zlib.pc   搜索結果:/usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc

                                          cat /usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc  版本信息會顯示出來 當前版本是Version:1.2.8 

                                 查看libpng版本:

                                          find /usr/ -name libpng  (當前版本1.2) 

                                 與Zlib:1.2.8之對應的libpng版本應該是1.5

                         解決方法:

                                 方法1:

                                        找到源碼,直接注釋掉。

                                 方法2:(按此方法,問題依舊,最后直接用了方法1,有空再研究此方法)

                                        安裝libpng:(需要先卸載老版本:libpng12, sudo apt-get remove libpng12-dev)

                                        下載地址:  https://sourceforge.net/projects/libpng/files/

                                        tar -xzvf  libpng-1.5.30.tar.gz  

                                        cd libpng-1.5.30.tar.gz  

                                       ./configure

                                       make check

                                       sudo make install

                                       sudo ldconfig

               問題10:

                      現象描述:

                             home/jim/miniconda3/include/python3.7m/pyport.h: 886:2:error:#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)

                      原因分析:

                             編譯前的./configure設置使用的是anaconda2(python2.7),在編譯時卻使用了python3.7m。

                      解決方法:

                             去除高級別的Python。   

               問題11:

                      現象描述:

                             external/boringssl/src/include/openssl/base.h:240:13: error: conflicting declaration 'typedef int CRYPTO_THREADID'

                      解決方法:

                             重命名交叉編譯SDK目錄x86_64_linux/boringssl為boringssl_old,以使代碼不編譯該包。

               問題12:

                      現象描述:

                             external/boringssl/src/crypto/internal.h:432:3: error: unknown type name 'pthread_rwlock_t'

                      解決方法: 

                             去除編譯選項 --conlyopt="-std=c99"

                             沒有顯示指定-std,gcc默認使用gnu89或gnu90標准,pthread_rwlock_t是gnu extension的一部分,指定使用c99會把gnu extension 禁用,造成pthread_rwlock_t未定義。

               問題13:

                      現象描述:

                             import enum # pylint:disable=g-bad-import-order

                             ImportError:No module named enum

                      解決方法: 

                             sudo apt-get install python-enum34

               問題14:           

                      現象描述:

                             import mock # pylint:disable=g-bad-import-order

                             ImportError:No module named mock 

                      解決方法: 

                             sudo apt-get install mock 

               問題15:           

                      現象描述:

                            更新SDK版本后,有編譯殘留信息,之前的路徑已更新,但在新路徑中並不存在。 

                      解決方法: 

                            1、 ll  ~/.cache/bazel       列出bazel_jim(當前主目錄)

                            2、 ll  ~/.cache/bazel/bazel_jim  列出各文件夾,其中包含自動生成的隨機文件夾,如果包含多個,可通過時間來判斷。找到最新的即可。

                            3、rm rf 之前生成的文件夾

                            4、sudo gedit /usr/include/python2.7/pyconfig.h

                                    更新相應文件路徑

               問題16:           

                      現象描述:

                             opt/fsl-bsp-x11/x86_64_linux/usr/include/python2.7/python.h:找不到python2.7/python-config32.h

                      解決方法: 

                             找到指定目錄,里面只有python-config64.h,直接復制一個文件,更名為python-config32.h

                             也可以找到定義WORDSIZE=32的地方,將 該值

 

                 問題17:   

                        Executing genrule @bazel_tools//tools/android:no_android_sdk_rpository_erro

                       在tensorflow的WORKSPACE文件夾下添加如下信息:

                           android_sdk_repository(

                                name="androidsdk",

                                api_level=28,//  設置為你安裝的SDK的最高版本,對應修改manifest.xml和target.

                                 build_tools_version="28.0.1",

                                 path="/home/jim/Android/Sdk",)   

               問題18:

                      在某些ARM平台,需要地址對齊,否則在程序運行時,訪問內存奇數地址或者未對齊地址,導致Crash

                      sudo gedit tensorflow/core/lib/gtl/inlined_vector.h +288

                     將T* unused_aligner 替換為  uint64_t unused_aligner   ,強制為8字節對齊。

               問題19:

                      問題現象:

                             /home/jim/tf2arm/sysroots/x86_64-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/ld:cannot find crti.o:No such file or directory

                             /home/jim/tf2arm/sysroots/x86_64-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/ld:cannot find crtbeginS.o:No such file or directory

                      原因分析:

                             在SDK包中查找這兩個文件,都可以正常找到,記錄下相應的全路徑;

                             CRT(C runtime)

                      嘗試方法1:

                              進入該目錄:/home/jim/tf2arm/sysroots/x86_64-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/ld,打開一個新的CMD窗口

                              建立軟連接:ln -s /home/jim/tf2arm/sysroots/x86_64-linu/cortexa9hf/usr/lib/arm-poky-linux-gnueabi/5.3.0/crtbeginS.o .

                                                    ln -s /home/jim/tf2arm/sysroots/x86_64-linu/cortexa9hf/usr/lib/crti.o . 

                              再次編譯失敗!

                     嘗試方法2:

                                  sudo find /usr/ -name crti*,找到相應的文件路徑:/usr/lib/x86_64-linux-gnu/  ,在CROSSTOOL里添加cxx_builtin_include_directory:"usr/lib/x8_64-linux-gnu"。

                              再次編譯失敗!   

                嘗試方法3:

                                 根據https://community.nxp.com/thread/391237,鏈接中有提供一些解決方法,但並未解決我的問題。

                     嘗試方法4:

                                  根據https://stackoverflow.com/questions/40233088/ld-cannot-find-crt1-o-no-such-file-or-directory

                                  需要在交叉編譯環境設置--sysroot=${STAGING_DIR_TARGET}/,調試了兩天,終於找到了設置的地方:

                                        在CROSSTOOL的toolchain,設置builtin_sysroot:“/opt/fsl-imx-x11/4.1.15-2.1.0/x86_64_polysdk-linux/cortexa9hf-neon-poky-linux-gnueabi”

                                  可以在編譯的環境變量里看到--sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/x86_64_polysdk-linux/cortexa9hf-neon-poky-linux-gnueabi

                                  問題得以解決!

                問題20: 

                       /opt/fsl-imx-x11/4.1.15-2.1.0/x86_64_polysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/ld:error: bazel-out/armv7-opt/bin/tensorflow/python/framework/fast_tensor_util.so uses VFP register arguments,bazel-out

                      /opt/fsl-imx-x11/4.1.15-2.1.0/x86_64_polysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/ld:failed to merge target specific data of file bazel-out/armv7-opt/bin/tensorflow/python/_objs/framework/fast_tensor_util.so/fast_tensor_util.pic.o

                       解決方法:

                              在CROSSTOOL的ARM toolchain,增加幾行編譯標志:

                                          compiler_flag: "-mfloat-abi=hard"

                                          compiler_flag: "-mfpu=vfpv3"           #具體內容需要對應具體ARM芯片,當前IMX6:armv7-a cortex-a9 vfpv3

                                          compiler_flag: "-funsafe-math-optimizations"

                問題21: 

                        undefined reference to 'void tensorflow:ConcatCPU<tensorflow::bfloat16>

                       解決方法:

                              在tensorflow/core/kernels/list_kernels.h中,注釋掉128行:ConcatCPU...

                問題22:

       在一台電腦上編譯通過的tensorflow拷貝到另外一台電腦上,無法編譯通過.

       bazel編譯pc版本tensorflow時,碰到兩個錯誤:

                                     第1個:external/nasm/include/error.h 找不到,需執行命令:sudo cp external/nasm/include/error.h  external/nasm/

            第2個:int_max_32 :redifinition in in /usr/include/google/protobuf/

                        bazel編譯arm版本tensorflow時,碰到以下錯誤:

           ./configure   配置python環境為:/usr/bin/python2.7  

           第一個:/home/jim/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/include-fixed/openssl/bn.h:fatal error: openssl/e_os2.h: No such file or directory

                           修改目錄:/home/jim/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/include-fixed/openssl 為openssl_old

                                                                   /home/jim/sysroots/x86_64-pokysdk-linux/cortexa9hf-neon-poky-linux-gnueabi/usr/include/openssl 為openssl_old

           第二個:int_max_32 :redifinition in in /usr/include/google/protobuf/

               修改目錄:/usr/include/google/protobuf 為protobuf_old

                                      第三個:/usr/include/python2.7/pyconfig.h:24:54: fatal error: arm-linux-gnueabihf/python2.7/pyconfig.h: No such file or directory

              打開文件:/usr/include/python2.7/pyconfig.h, 去掉前綴:arm-linux-gnueabihf/

               用了一周時間終於解決完所有編譯問題,上張圖,在此MARK一下!

                      

                                         

                                   

 

 

                          

                注:bazel clean --expunge   (盡量少用,使用后,會清除生成的文件~/.cache/bazel/bazel_jim/7924169126bef9c95805dc831e19e9c3)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM