愚かな質問ですが、おそらくヘッダーがありませんが、マニュアルページには#include <linux/random.h>
が必要です。getrandom()がコンパイルされないのはなぜですか?
#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;
}
エラーは次のとおりです。
[email protected]:~/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に失敗した)
[email protected]:~/lunch/bitarray$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
[email protected]:~/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
をうん、あなたのコンパイルエラーがその関数のプロトタイプは、ヘッダーにされていないと正確に一致しています。ドキュメンテーション、ええ? – Bathsheba
@MichaelWalz 'chris @ purple:〜/ lunch/bitarray $ make && ./bitarray clang -g -Wall -Wpedantic -Werror -std = c11 -O2 -save-temps bitarray.c -oビット配列 bitarray.c: 5:10:致命的なエラー: 'sys/random.h'ファイルが見つかりません #include ' –
fadedbee
ここにマンページは' 'と言っています - それは間違っています:またはディレクトリ! –