Solved

RedHat 6.2 : C Program getdents ld error

Posted on 2001-06-27
1
407 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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