Solved

RedHat 6.2 : C Program getdents ld error

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

22 Experts available now in Live!

Get 1:1 Help Now