LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   trouble using arc4random() in C program on Ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/trouble-using-arc4random-in-c-program-on-ubuntu-729598/)

Greg Marks 05-30-2009 09:38 PM

trouble using arc4random() in C program on Ubuntu
 
I am having trouble with arc4random on Ubuntu 9.04. I installed the libbsd-dev package, and "man arc4random" does bring up the man page. But if I try to compile this program:

#include <stdio.h>
#include <stdlib.h>

main()
{
int x;
x=arc4random();
printf("%i\n", x);
return 0;
}

I get the following result:

56$gcc -o test test.c
/tmp/ccQeErYt.o: In function `main':
test.c:(.text+0xe): undefined reference to `arc4random'
collect2: ld returned 1 exit status

How do I get this to work?

P.S. I have also posted this question at ubuntuforums.org (I hope it's not considered unethical for some reason to post it in two places). I've received no response there.

osor 05-30-2009 09:55 PM

Quote:

Originally Posted by Greg Marks (Post 3557862)
$gcc -o test test.c

You need to link to libbsd. Try this:
Code:

$ gcc -lbsd -o test test.c

Greg Marks 05-31-2009 12:08 AM

That solves my problem. Thank you very much for your help.


All times are GMT -5. The time now is 03:51 PM.