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

在尝试编译OHOS时遇到portability.h错误,原因是glibc版本过旧。解决方法是升级到glibc 2.25及以上版本,该版本引入了sys/random.h头文件。可以参照教程在CentOS上更新glibc,或者使用busybox作为shell解释器作为替代方案。

报错内容如下:

[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 <sys/random.h>
[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_淡竹云开的博客-优快云博客_centos glibc

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

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

busybox作为shell解释器

user@debian:~/ModSecurity$ ./build.sh libtoolize: putting auxiliary files in '.'. libtoolize: copying file './ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build'. libtoolize: copying file 'build/libtool.m4' libtoolize: copying file 'build/ltoptions.m4' libtoolize: copying file 'build/ltsugar.m4' libtoolize: copying file 'build/ltversion.m4' libtoolize: copying file 'build/lt~obsolete.m4' configure.ac:50: installing './compile' configure.ac:45: installing './missing' examples/multiprocess_c/Makefile.am: installing './depcomp' src/Makefile.am:70: warning: wildcard actions/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/ctl/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/data/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/disruptive/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/transformations/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard debug_log/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard audit_log/writer/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard collection/backend/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard operators/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard parser/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard request_body_processor/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard utils/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard variables/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard engine/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard *.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/ctl/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/data/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/disruptive/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard actions/transformations/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard debug_log/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard audit_log/writer/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard collection/backend/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard operators/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard parser/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard request_body_processor/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard utils/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard variables/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard engine/*.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) src/Makefile.am:70: warning: wildcard *.h: non-POSIX variable name src/Makefile.am:70: (probably a GNU make extension) user@debian:~/ModSecurity$
06-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值