linux交叉编译nss3,nspr库精讲

  • 交叉编译nss库

编译QT时发现要求NSS >= 3.26 is required. 而系统里的nss库只有2.x ,故查阅了相关资料,发现对nss交叉编译的资料较少.

文中涉及到交叉编译器和库的路径以自己实际路径为准.


  • nss以及依赖库下载地址

nss-3.*.tar.gz.
记得下载补丁
在这里插入图片描述

NSS Dependencies Required:
nspr-4.x.tar.gz.
PS:当时下载的是nss3.50,nspr4.25


  • 交叉编译nspr流程

首先交叉编译nss的依赖库nspr

#此目录用gcc编译 cd ./nspr_x64/nspr/ sed -ri 's#^(RELEASE_BINS =).*#\1#' pr/src/misc/Makefile.in sed -i 's#$(LIBRARY) ##'           
config/rules.mk ./configure --with-pthreads --enable-64bit
--with-mozilla  make
#安装是因为等会还要make 64位的nss库 make install

#此目录用交叉编译器编译 cd ../../nspr-4.25/nspr/ sed -ri 's#^(RELEASE_BINS =).*#\1#' pr/src/misc/Makefile.in sed -i 's#$(LIBRARY) ##'            config/rules.mk

./configure --with-pthreads  \
--prefix=/opt/hisi-linux/x86-arm/lib/nspr \
--host=arm-himix200-linux   \ CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc \
CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++ 

make
#此时会报错提示../../../config/./nsinstall: ../../../config/./nsinstall: 无法执行二进制文件
#原因用32位交叉编译器生成的可执行文件nsinstall,pc无法执行
#解决方法:用gcc编译生成的文件进行替换 cp ../../nspr_x64/nspr/config/nsinstall ./config
#继续make make

make install


依赖库终于装完了,剩下开始交叉编译nss.


  • 交叉编译nss流程

PS:下载nss库的同时还得下载nss补丁


#此目录用gcc编译 cd ./nss_x64

#用patch命令打补丁 patch -Np1 -i ../nss-3.50-standalone-1.patch 

cd nss
#注意自己刚刚用gcc安装的nspr库位置 make -j1 BUILD_OPT=1                  \   NSPR_INCLUDE_DIR=/usr/include/nspr   \   NSPR_LIB_DIR=/usr/lib/nspr \ 
USE_STATIC_RTL=1 \   USE_SYSTEM_ZLIB=1                   \  
ZLIB_LIBS=-lz                       \   NSS_ENABLE_WERROR=0           
\   $([ -f /usr/include/sqlite3.h ] && echo NSS_USE_SYSTEM_SQLITE=1) \
$([ $(uname -m) = x86_64 ] && echo USE_64=1)   

#此目录用交叉编译器编译 cd ../../nss-3.50 

patch -Np1 -i ../nss-3.50-standalone-1.patch 

cd nss

#参数没指定zlib和sqlite库的路径,需要确保自己的交叉编译器能找到. make -j1 \   CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc \  
CCC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++ \   BUILD_OPT=1 \  
NSPR_INCLUDE_DIR=/opt/hisi-linux/x86-arm/lib/nspr/include/nspr \  
NSPR_LIB_DIR=/opt/hisi-linux/x86-arm/lib/nspr/lib \  
NSS_USE_SYSTEM_SQLITE=1 \   NSS_ENABLE_WERROR=0 \   USE_SYSTEM_ZLIB=1
\   USE_STATIC_RTL=1 \   OS_TEST=arm    
#此时make报错:/bin/sh: 行 2: 
#../../coreconf/nsinstall/Linux5.3_aarch64_arm-himix200-linux-gcc_glibc_PTH_64_OPT.OBJ/nsinstall:
无法执行二进制文件: 可执行文件格式错误
#报错原因与nspr库相同,所以也用pc的gcc编译一个生成可执行文件进行替换

cp
../../nss_x64/nss/coreconf/nsinstall/Linux5.3_x86_64_cc_glibc_PTH_64_OPT.OBJ/nsinstall
./coreconf/nsinstall/Linux5.3_arm_arm-himix200-linux-gcc_glibc_PTH_OPT.OBJ/nsinstall


#继续上面的执行make设置 "make"
#然后还会出错,不过是过了好一会
#arm_arm-himix200-linux-gcc_glibc_PTH_OPT.OBJ/shlibsign: 无法执行二进制文件: 可执行文件格式错误

cp
../../nss_x64/nss/cmd/shlibsign/Linux5.3_x86_64_cc_glibc_PTH_64_OPT.OBJ/shlibsign
./cmd/shlibsign/Linux5.3_arm_arm-himix200-linux-gcc_glibc_PTH_OPT.OBJ/shlibsign

#继续上面的执行make设置 "make"



#成功
  • 可能遇到的其他错误

情况一:

arm-himix200-linux-gcc: error: unrecognized argument in option '-march=armv8-a+crypto'
arm-himix200-linux-gcc: error: unrecognized command line option '-m32'

原因:遇到这两个错误都是因为交叉编译器和所选的设备类型不匹配.

情况二:

 [../../../dist/Linux5.3_arm_arm-himix200-linux-gcc_glibc_PTH_OPT.OBJ/lib/libsoftokn3.chk] Error 1

原因:makefie没法生成chk文件.
解决办法:

  • 方法一:(具体参考评论区的方法).在nss-3.53/nss/cmd/shlibsign/Makefile 90行附近可以看到ifeq ($(CROSS_COMPILE),1)
    进行处理:在OS_TARGET=Android的时候可以编译时候指定CROSS_COMPILE=1,而其他平台的话需要手动指定CROSS_COMPILE=1.
  • 方法二:手动拷贝chk到目标生成目录,已达到跳过此步骤的目的.
  • 方法三:删除makefie中生成chk文件的部分代码

此时安装完成,需要转移库的位置,路径根据自己需求调整即可.

../dist/Linux5.3_arm_arm-himix200-linux-gcc_glibc_PTH_OPT.OBJ
# install -v -m755 lib/*.so              /lib/nss/lib
# install -v -m644 lib/{*.chk,libcrmf.a} /lib/nss/lib
# install -v -m755 -d                    /lib/nss/include
# cp -v -RL ../{public,private}/nss/*    /lib/nss/include
# chmod -v 644                           /lib/nss/*
# install -v -m755 bin/{certutil,nss-config,pk12util} /opt/hisi-linux/x86-arm/arm-himix200-linux/bin
# install -v -m644 lib/pkgconfig/nss.pc  /opt/hisi-linux/x86-arm/arm-himix200-linux/target/usr/lib/pkgconfig
  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 35
    评论
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 35
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

泡沫o0

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值