Problem with Header files.

This is a discussion on Problem with Header files. within the C Programming forums, part of the General Programming Boards category; HI, I have a bit of problem in compiling my c program. When I compile my program i get the ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30

    Problem with Header files.

    HI,
    I have a bit of problem in compiling my c program. When I compile my program i get the following error.

    Code:
    ldirfunc.c:13: error: conflicting types for opendir
    /usr/include/dirent.h:135: error: previous declaration of opendir was here
    Program snippet:

    Code:
    #include "Dirent.h"
    #include<sys/stat.h>
    #include<string.h>
    #include<sys/types.h>
    #include "syscall.h"
    #include<fcntl.h>
    #include<sys/dir.h>
    #include<malloc.h>
    
    Dir *opendir(char *dirname){
      int fd;
      struct stat stbuf;
      Dir *dp;
      if((fd=open(dirname,O_RDONLY,0)) == -1 || fstat(fd,&stbuf) == -1 ||
          ((stbuf.st_mode * S_IFMT) != S_IFDIR) ||
          (dp = (Dir *) malloc (sizeof(Dir))) != NULL)
        return NULL;
      dp->fd=fd;
      return dp;
    }
    What I understand from the error, that my opendir function is already declared in the dirent.h(not the one i use, Dirent.h). dirent.h must have been included somewhere, may in some of the header files that i use.
    Do we have any option while compiling to neglect these redefinition errors? I want to use my opendir function and not the predefined one.
    I am a beginner in c programming, so please excuse me for my mistakes.

    thanks to all!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    I think the simplest solution is to rename your function, e.g., use a chakra prefix and name it chakra_opendir().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,769
    > #include "Dirent.h"
    Is this your dirent.h file, or the one belonging to the system?
    If it's yours, give it a different name, because relying solely on a case-sensitive filename won't work on say a windows box come porting time.

    > #include "syscall.h"
    I thought you only needed this if you were talking directly to the OS.

    > #include<malloc.h>
    malloc is prototyped in stdlib.h

    > dp = (Dir *) malloc (sizeof(Dir))
    There's no need to cast malloc in a correct C program.
    See the FAQ for other reasons why it really is not helpful to cast malloc.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    1
    the mastring in c.(lawkumar)

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    India
    Posts
    30
    Thanks to all.
    I will try the suggestions provided and see if i can succeed.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by lawkumar3289 View Post
    the mastring in c.(lawkumar)
    Huh? What's a 'mastring'?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 05 Express Header Files
    By comwiz in forum C++ Programming
    Replies: 14
    Last Post: 02-16-2006, 07:00 AM
  2. Header Files
    By Volair in forum C Programming
    Replies: 2
    Last Post: 12-09-2005, 10:51 AM
  3. need help with menu program and header files
    By DFC in forum C++ Programming
    Replies: 12
    Last Post: 12-07-2005, 12:09 PM
  4. Missing header files and libraries with Borland
    By quagsire in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2003, 06:19 AM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21