Solved

RedHat 6.2 : C Program getdents ld error

Posted on 2001-06-27
1
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux , how do I append to the PATH and not mess up the existing PATH 4 81
Problem to command 8 103
Problem to line 1 65
Help with Ubuntu 14.04 LTS 10 142
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…

751 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