其他分享
首页 > 其他分享> > 海思hi3518ev300 编译uclibc

海思hi3518ev300 编译uclibc

作者:互联网

uclibc编译

当海思自带的uclibc库无法满足要求时,可以通过uclibc源码编译出满足要求的libc版本。如海思自带的uclibc库不支持LD_PRELOAD选项时,可以通过编译uclibc源码使其支持LD_PRELOAD选项。

查看现有版本

编译的uclibc版本最好和当前系统的libc版本匹配,这样移植后续应用程序也比较方便,可以通过如下命令查看当前板子上的uclibc版本,我的板子上uclibc版本是0.9.33.2。

/nfs/h18e3 # ls /lib/ld*
/lib/ld-uClibc-0.9.33.2.so  /lib/ld-uClibc.so.0

下载源码

从如下地址下载对应版本的uclibc:

https://uclibc.org/downloads/

编译选项

首先解压下载的uclibc源码压缩包:

tar xf uClibc-0.9.33.2.tar.bz2
cd uClibc-0.9.33.2/
make menuconfig

其次设置对应的交叉编译器与编译选项:

  1. 将"Target Architecture"设置为"arm"。
  2. 设置"Target Architecture Features and Options"中的"Target Processor Endianness"为"Little Endian"。
  3. 设置"Target Architecture Features and Options"中的"Linux kernel header location"为: “/opt/hisi-linux/x86-arm/arm-himix100-linux/target/usr/include/”(注:需要依据海思交叉编译器的安装目录自行设置)。
  4. 设置"Development/debugging options"中的"Cros-compiling toolchain prefix"为"arm-himix100-linux-"。
  5. 设置"Development/debugging options"中的"Extra CFLAGS"为"-mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4 -fno-aggressive-loop-optimizations"。
  6. 依照项目的需求自行打开/关闭其他相关编译选项,如:

make选项设置完毕,使用如下命令编译,并查看生成的so文件:

[cxm@cxm-desktop uClibc-0.9.33.2]$ make -j
[cxm@cxm-desktop uClibc-0.9.33.2]$ ls ./lib/*so*
./lib/ld-uClibc-0.9.33.2.so  ./lib/libcrypt.so.0      ./lib/libm-0.9.33.2.so    ./lib/libpthread-0.9.33.2.so  ./lib/libresolv.so.0         ./lib/libutil.so
./lib/ld-uClibc.so           ./lib/libc.so            ./lib/libm.so             ./lib/libpthread.so           ./lib/librt-0.9.33.2.so      ./lib/libutil.so.0
./lib/ld-uClibc.so.0         ./lib/libc.so.0          ./lib/libm.so.0           ./lib/libpthread.so.0         ./lib/librt.so
./lib/ld-uClibc.so.lds       ./lib/libdl-0.9.33.2.so  ./lib/libnsl-0.9.33.2.so  ./lib/libresolv-0.9.33.2.so   ./lib/librt.so.0
./lib/libcrypt-0.9.33.2.so   ./lib/libdl.so           ./lib/libnsl.so           ./lib/libresolv.a             ./lib/libuClibc-0.9.33.2.so
./lib/libcrypt.so            ./lib/libdl.so.0         ./lib/libnsl.so.0         ./lib/libresolv.so            ./lib/libutil-0.9.33.2.so

编译应用程序

uclibc编译成功后,需要将生成的so文件拷贝到交叉编译器对应的目录,并重新编译你的应用程序。使用如下命令确认需要拷贝的目录:

[cxm@cxm-desktop uClibc-0.9.33.2]$ arm-himix100-linux-gcc -print-file-name=libdl.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/libdl.so
[cxm@cxm-desktop uClibc-0.9.33.2]$ file /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/libdl.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/libdl.so: symbolic link to ../../lib/libdl.so.0
[cxm@cxm-desktop uClibc-0.9.33.2]$ ls /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/*9.33.2*so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/ld-uClibc-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libcrypt-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libdl-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libm-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libnsl-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libpthread-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libresolv-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/librt-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libuClibc-0.9.33.2.so
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/libutil-0.9.33.2.so
[cxm@cxm-desktop uClibc-0.9.33.2]$ sudo mkdir -p  /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/bak
[cxm@cxm-desktop uClibc-0.9.33.2]$ sudo cp /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/*9.33.2*so /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/bak
[cxm@cxm-desktop uClibc-0.9.33.2]$ sudo cp ./lib/*9.33.2*so /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/usr/lib/../../lib/

将so拷贝到对应的目录后,需要重新链接应用程序,如果应用程序使用了c++,建议使用静态链接c++库,即在编译时添加选项:

arm-himix100-linux-g++ -static-libstdc++ ...

运行

将编译的所有so文件拷贝到开发板对应的目录,使用如下命令执行应用程序:

/nfs/h18e3 # ls *9.33.2*so
ld-uClibc-0.9.33.2.so   libdl-0.9.33.2.so       libnsl-0.9.33.2.so      libresolv-0.9.33.2.so   libuClibc-0.9.33.2.so
libcrypt-0.9.33.2.so    libm-0.9.33.2.so        libpthread-0.9.33.2.so  librt-0.9.33.2.so       libutil-0.9.33.2.so
/nfs/h18e3 # LD_PRELOAD=hook.so ./ld-uClibc-0.9.33.2.so --library-path ./ ./yourapp yourargs 2>&1 | tee log

标签:0.9,hi3518ev300,..,33.2,so,lib,uclibc,海思,arm
来源: https://blog.csdn.net/chenxiemin/article/details/106460508