简体   繁体   English

function 'rand_r' 的隐式声明

[英]implicit declaration of function ‘rand_r’

I know there are a lot of questions with a similar title, but so far I have not found one that could solve my situation.我知道有很多类似标题的问题,但到目前为止我还没有找到一个可以解决我的情况的问题。

When making the file, I got prompted with制作文件时,我收到提示

warning: implicit declaration of function ‘rand_r’ [-Wimplicit-function-declaration]

But I have already included stdlib.h and unistd.h , why is it still happening?但是我已经包含了stdlib.hunistd.h ,为什么它还在发生? Is it because of the makefile?是因为makefile吗?

I am running this on Linux and my makefile is roughly as follows:我在 Linux 上运行这个,我的 makefile 大致如下:

prog: prog.o
    gcc -g -o $@ $^ -lpthread

%.o:%.c *.h
    gcc -ansi -pedantic -Wimplicit-function-declaration -Wreturn-type -g -c $< -o $@

Thank you谢谢

rand_r() manpage reads: rand_r()内容如下:

The functions rand() and srand() conform to SVr4, 4.3BSD, C89, C99, POSIX.1-2001.函数 rand() 和 srand() 符合 SVr4、4.3BSD、C89、C99、POSIX.1-2001。 The function rand_r() is from POSIX.1-2001. function rand_r() 来自 POSIX.1-2001。 POSIX.1-2008 marks rand_r() as obsolete. POSIX.1-2008 将 rand_r() 标记为已过时。

Your compilation options specify -ansi (C89/C90) thus limiting you to rand() and srand() .您的编译选项指定-ansi (C89/C90) 从而将您限制为rand()srand()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM