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? Is it because of the makefile?
I am running this on Linux and my makefile is roughly as follows:
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:
The functions rand() and srand() conform to SVr4, 4.3BSD, C89, C99, POSIX.1-2001. The function rand_r() is from POSIX.1-2001. POSIX.1-2008 marks rand_r() as obsolete.
Your compilation options specify -ansi
(C89/C90) thus limiting you to rand()
and srand()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.