LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 10:38 PM   #1
Greg Marks
LQ Newbie
 
Registered: May 2009
Posts: 15

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, 10:55 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 75
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, 01:08 AM   #3
Greg Marks
LQ Newbie
 
Registered: May 2009
Posts: 15

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:23 PM
ASM Program Trouble Mercurius Programming 6 11-08-2006 10:18 PM
having trouble with the do while loop in program mshinska Programming 2 10-08-2005 11:18 PM
trouble configuring a program minm Linux - Newbie 12 03-28-2005 05:33 PM
Trouble compiling QT program vapebait Programming 2 11-25-2003 03:23 PM


All times are GMT -5. The time now is 02:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration