Issues compiling multiple c files.

This is a discussion on Issues compiling multiple c files. within the C Programming forums, part of the General Programming Boards category; Here are the c files that I'm trying to compile. Please note that I haven't cleaned up the code yet. ...

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    Issues compiling multiple c files.

    Here are the c files that I'm trying to compile. Please note that I haven't cleaned up the code yet.

    Code:
    [cdalten@localhost YAPP]$ more diren.h
    #define MAX 14
    
    typedef struct {
      long ino;
      char name[MAX + 1];
    } Dirent;
    
    typedef struct {
      int fd;
      Dirent d;
    } DIR;
    Code:
    [cdalten@localhost YAPP]$ more opendir.c
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    
    #include "diren.h"
    
    #define PATH "/home/cdalten/oakland"
    
    DIR *opendirectory(void) {
      int fd;
    
      DIR *dp;
      if ( (fd = open(PATH, O_RDONLY)) < 0) {
        perror(PATH);
        exit(EXIT_FAILURE);
      }
    
      dp = (DIR *)malloc(sizeof(DIR));
    
      dp->fd = fd;
      return dp;
    }
    
    int main(void) {
    
      size_t n;
      char buf[BUFSIZ];
    
      DIR *dfp;
    
      dfp = opendirectory();
    
      /*if ( (fd = open(PATH, O_RDONLY)) < 0) {
        perror(PATH);
        exit(EXIT_FAILURE);
      }
    
      while ((n = read(fd, buf, BUFSIZ)) > 0) {
        if (write(1, buf, n) != n) {
          fprintf(stderr, "Can't call write\n");
          exit(EXIT_FAILURE);
        }
      }
    
      close(fd);*/
    
      exit(EXIT_SUCCESS);
    }
    [cdalten@localhost YAPP]$
    Code:
    [cdalten@localhost YAPP]$ more readdir.c
    #include <sys/dir.h>
    #include "diren.h"
    
    DIR *readdirectory() {
      struct direct dirbuf;
      static Dirent d;
    }
    [cdalten@localhost YAPP]$
    And here is the error that I get.....
    [cdalten@localhost YAPP]$ gcc -g opendir.c readdir.c -o readit
    In file included from readdir.c:2:
    diren.h:11: error: conflicting types for ‘DIR’
    /usr/include/dirent.h:128: error: previous declaration of ‘DIR’ was here
    [cdalten@localhost YAPP]$
    What am I doing wrong here?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What are you doing wrong? Why are you redefining system names?

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    I knew that. I really did.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. header files and multiple files
    By Dedalus in forum C Programming
    Replies: 5
    Last Post: 06-16-2009, 09:21 AM
  2. Compiling Multiple files in a single Project
    By pdwivedi in forum C Programming
    Replies: 2
    Last Post: 10-08-2007, 05:14 AM
  3. Windows shell commands - multiple files
    By Magos in forum Tech Board
    Replies: 3
    Last Post: 02-28-2006, 12:56 AM
  4. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  5. Multiple files using RHIDE
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-05-2001, 06:39 PM

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