gpt4 book ai didi

c - 为什么 getrandom() 不编译?

转载 作者:太空狗 更新时间:2023-10-29 15:28:24 26 4
gpt4 key购买 nike

<分区>

愚蠢的问题,我可能缺少标题,但手册页说我只需要 #include <linux/random.h> .

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <linux/random.h>

#define BITS 8192
#define BYTES (BITS >> 3)

int main() {
uint8_t array[BYTES];

printf("started...");
int r = getrandom(array, BYTES, 0);
if (r) exit(1);

return 0;
}

错误是:

chris@purple:~/lunch/bitarray$ make && ./bitarray 
clang -g -Wall -Wpedantic -Werror -std=c11 -O2 -save-temps bitarray.c -o bitarray
bitarray.c:13:10: error: implicit declaration of function 'getrandom' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
int r = getrandom(array, (8192 >> 3), 0);
^
1 error generated.
Makefile:10: recipe for target 'bitarray' failed
make: *** [bitarray] Error 1

(在 gcc 中也失败。)

chris@purple:~/lunch/bitarray$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
chris@purple:~/lunch/bitarray$ uname -a
Linux purple 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com