C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-11-2009, 03:55 PM   #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.....
Quote:
[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?
Overworked_PhD is offline   Reply With Quote
Old 10-11-2009, 04:01 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 10,163
What are you doing wrong? Why are you redefining system names?
tabstop is offline   Reply With Quote
Old 10-11-2009, 04:25 PM   #3
Banned
 
Join Date: May 2007
Location: Berkeley, CA
Posts: 329
I knew that. I really did.
Overworked_PhD is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:18 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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