Hi Everyone,

I am trying to compile code for a FAT file system implementation. I define my struct as

struct DirEntry
{
    uint8_t status PACKED;
    uint32_t start_block PACKED;
    uint32_t num_blocks PACKED;
    uint32_t fsize PACKED;
    MC_Time created PACKED;
    MC_Time modified PACKED;
    uint8_t fname[31] PACKED;
    uint8_t unused[6] PACKED;
};

typedef struct DirEntry d_Entry;

in a file called common.h
then in a file called common.c I create the method as follows:

void get_DEntry(d_Entry *DEntry, FILE *image)
{

    size_t Sz = 64;
    size_t Ct = 1;
    fread(DEntry,Sz,Ct,image);
    DEntry->start_block = ntohl(DEntry->start_block);
    DEntry->num_blocks = ntohl(DEntry->num_blocks);
    DEntry->fsize = ntohl(DEntry->fsize);
    DEntry->created.year = ntohs(DEntry->created.year);
    DEntry->modified.year = ntohs(DEntry->modified.year);
}

I envoke the method by doing:

get_SBlock(&SBlock, image);

When I compile I get the following error:

In function `get_DEntry':
: multiple definition of `get_DEntry'
common.o(.text+0x0): first defined here

I was hoping someone could help me figure out why I'm getting this error.

Thanks

Mindy

Edited 3 Years Ago by pyTony: fixed formatting

Looks like you did a #include "common.c" when you should have done #include "common.h"

The include is common.h
The files compile seperately, but have errors when linking with the file that calls the mehod.
gcc -o assign4 common.o diskinfo.o

The errors are:
diskinfo.o(.text+0x0): In function `get_DEntry':
: multiple definition of `get_DEntry'
common.o(.text+0x0): first defined here
diskinfo.o(.text+0xa0): In function `get_SBlock':
: multiple definition of `get_SBlock'
common.o(.text+0xa0): first defined here
collect2: ld returned 1 exit status


No idea whats goin on.

This article has been dead for over six months. Start a new discussion instead.