LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2009, 09:38 PM   #1
Greg Marks
LQ Newbie
 
Registered: May 2009
Posts: 16

Rep: Reputation: 2
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.
 
Old 05-30-2009, 09:55 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Greg Marks View Post
$gcc -o test test.c
You need to link to libbsd. Try this:
Code:
$ gcc -lbsd -o test test.c
 
Old 05-31-2009, 12:08 AM   #3
Greg Marks
LQ Newbie
 
Registered: May 2009
Posts: 16

Original Poster
Rep: Reputation: 2
That solves my problem. Thank you very much for your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I'm having trouble with this program.... rec3g Programming 14 03-16-2008 09:23 PM
ASM Program Trouble Mercurius Programming 6 11-08-2006 09:18 PM
having trouble with the do while loop in program mshinska Programming 2 10-08-2005 10:18 PM
trouble configuring a program minm Linux - Newbie 12 03-28-2005 04:33 PM
Trouble compiling QT program vapebait Programming 2 11-25-2003 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration