> 文档中心 > [OHOS ERROR] portability.h:309:24: fatal error: sys/random.h: No such file or directory

[OHOS ERROR] portability.h:309:24: fatal error: sys/random.h: No such file or directory

报错内容如下:

[OHOS ERROR] FAILED: obj/third_party/toybox/toys/other/toybox.reset.o [OHOS ERROR] ccache arm-linux-gnueabihf-gcc -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -DOHOS_DEBUG -D_FORTIFY_SOURCE=2 -D__linux__ -D__LINUX__ -I../../../third_party/toybox -Os -mfpu=neon-vfpv4 -mfloat-abi=hard -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -fno-common -fno-builtin -fno-strict-aliasing -Wall -funwind-tables -fasynchronous-unwind-tables -fsigned-char -fstack-protector-all -fPIE -std=gnu11 -Wall -Wundef -Wno-char-subscripts -Wno-implicit-function-declaration -Wno-unused-variable -Wno-unused-value -Wno-incompatible-pointer-types -Wno-int-conversion -Wno-sign-compare -Wno-format -Wno-unused-result -Os -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fPIE -funsigned-char -c ../../../third_party/toybox/toys/other/reset.c -o obj/third_party/toybox/toys/other/toybox.reset.o[OHOS ERROR] In file included from ../../../third_party/toybox/toys.h:9:0,[OHOS ERROR]    from ../../../third_party/toybox/toys/other/reset.c:17:[OHOS ERROR] ../../../third_party/toybox/lib/portability.h:309:24: fatal error: sys/random.h: No such file or directory[OHOS ERROR]  #include [OHOS ERROR]    ^[OHOS ERROR] compilation terminated.[OHOS ERROR] you can check build log in /home/openharmony/out/MyBoard/My_Product_demo/build.log

根据搜索发现

这个错误是因为libc的版本太古老了,解决方法是升级glibc的版本: linux - getrandom syscall in C not found - Stack Overflow

在2017年的glibc 2.25版本中增加了头文件,详情:Siddhesh Poyarekar - The GNU C Library version 2.25 is now available

在centos上安装最新的glibc的教程参考文章:在centos上安装最新的glibc_淡竹云开的博客-CSDN博客_centos glibc

因为指定编译器所以替代shell启动脚本方案

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器