Solved

RedHat 6.2 : C Program getdents ld error

Posted on 2001-06-27
1
405 Views
Last Modified: 2007-12-19
Hi!
I am recieving an ld error when compiling a simple C program using the "getdents" function. I'm hoping that one of the experts out there can decode & fix the following ld error:
/tmp/ccO4jRVF.o: In function `main':
/tmp/ccO4jRVF.o(.text+0x50): undefined reference to `getdents'
collect2: ld returned 1 exit status

Here is a copy of my program:
/**********************************
 * Program Name : getdents_tester.c
 * Created      : LL 06/05/01
 **********************************/

#include <stdio.h>
#include <unistd.h>
#include <linux/types.h>
#include <linux/dirent.h>
#include <linux/unistd.h>

struct dirent *dirent_p;
unsigned      int fd;
unsigned      int count;
int           rc;

main()
{
   fd = 0x01;
   count = 0x200;
   printf("fd = 0x%x, count = 0x%x\n",fd,count);
   printf("Calling getdents...\n");
   rc = getdents(fd,dirent_p,count);
   printf("getdents returned 0x%x\n",rc);
   return(rc);
}

Good Luck!
Thanks!
lori-Ann :-)
0
Comment
Question by:lleahy
1 Comment
 
LVL 5

Accepted Solution

by:
bryanh earned 50 total points
ID: 6249509
First of all, did you compile cleanly with gcc -Wall?  In particular, it's important to know you don't have any implicitly defined functions.  Using gcc -Wall all the time can save you a lot of pain.

In this case, I believe you'll find that getdents() is not a GNU C library function, so you can't use it like this.  (The fact that you have to include <linux/...> files, which are Linux kernel interfaces, also tells you this).  You can use the _syscall3() C library function as described in the getdents() Linux man page, or you can use the POSIX function for reading directories, readdir().  readdir() uses the getdents() kernel service to do its job.  Not to be confused with the readdir() system call, which is a kernel service that the readdir() C library function used to use and still exists for backward compatibility.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is an introductory video for CloudBerry Managed Backup. You will learn how to sign up with the service and get started in a few minutes.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now