0

I have a makefile that content like this:

ALL: Compile Execute

Compile:
    gcc -I ./include/ -o ./lib/Uretim.o -c ./src/Uretim.c
    gcc -I ./include/ -o ./lib/AUretim.o -c ./src/AUretim.c
    gcc -I ./include/ -o ./lib/BUretim.o -c ./src/BUretim.c
    gcc -I ./include/ -o ./lib/Taktik.o -c ./src/Taktik.c
    gcc -I ./include/ -o ./lib/Ataktik.o -c ./src/Ataktik.c
    gcc -I ./include/ -o ./lib/Btaktik.o -c ./src/Btaktik.c
    gcc -I ./include/ -o ./lib/Koloni.o -c ./src/Koloni.c
    gcc -I ./include/ -o ./lib/Oyun.o -c ./src/Oyun.c
    @echo :"denem"
    gcc -I ./include/ -o ./bin/Test ./lib/Uretim.o ./lib/AUretim.o ./lib/BUretim.o ./lib/Taktik.o ./lib/Ataktik.o ./lib/Btaktik.o ./lib/Koloni.o ./lib/Oyun.o ./src/Test.c
    @echo :"denem"
Execute:
    ./bin/Test

at the line that come after first echo I get redefiniton error for all headers. How can I fix this problem?

sample error:

D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./lib/AUretim.o:AUretim.c:(.bss+0x0): multiple definition of `URETIM'; ./lib/Uretim.o:Uretim.c:(.bss+0x0): first defined here 

my Uretim.h file:

#ifndef URETIM_H
#define URETIM_H

struct URETIM
{
    int deger;
    void (*degerdegistirU)(struct URETIM *,int );
    int (*Uret)(struct URETIM *);
    void (*yoketU)(struct URETIM *);
    int (*degerdondurU)();
}URETIM;

typedef struct URETIM *Uretim;

#endif

AUretim.h:

#ifndef AURETIM_H
#define AURETIM_H



#include "Uretim.h"
struct AURETIM
{
    
    struct URETIM * super;
    int (*degerDondurUA)(struct AURETIM *);
    void (*AyoketU)(struct AURETIM *);
}AURETIM;

typedef struct AURETIM *Auretim;

#endif

koloni.h:

#ifndef KOLONI_H
#define KOLONI_H



#include "ATaktik.h"
#include "BTaktik.h"
#include "AUretim.h"
#include "BUretim.h"

struct KOLONI
{
  
    ATaktik atak;
    BTaktik batak;
    Auretim auret;
    Buretim BUret;
    int (* stokgetir)(struct KOLONI *);
    int ( * populasyongetir)(struct KOLONI *);
    char (*sembolgetir)(struct KOLONI *);
    void (*Uretimyap)(struct KOLONI *);
    int (*Savasyap)(struct KOLONI *,struct KOLONI *);
    void (*Populasyonduzenle)(struct KOLONI *,int);
    void (*stokDuzenle)(struct KOLONI *,int);
}KOLONI;

typedef struct KOLONI *Koloni;


#endif

Oyun.h:

#ifndef OYUN_H
#define OYUN_H

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<time.h>

#include "Koloni.h"

struct OYUN
{
    void (*kolonisavasi)(struct KOLONI *,struct KOLONI *);
}OYUN;

typedef struct OYUN *Oyun;
// typedef struct KOLONI *Koloni;

Oyun oyunolustur();
#endif

I have give my header files content and their including. When I have create object file for each source every think okey.But if I link this object file to Test.c that have main function I take sample error

goOdyaga
  • 5
  • 2
  • 1
    You probably defined a variable in a header file. You need to *declare* it in a header and *define* it in exactly one .c file. – dbush May 18 '23 at 17:10
  • URETIM that I give in the sample error is a struct and I have declare it one time for every header file. My heades only contain struct declearition and source file. I can give you sample definition. I have AUretim struct and this struct has Uretim struct in it . Uretim struct in another header file and I include this header in AUretim header for using. when makefile run this command: gcc -I ./include/ -o ./bin/Test ./lib/Uretim.o ./lib/AUretim.o ./lib/BUretim.o ./lib/Taktik.o ./lib/Ataktik.o ./lib/Btaktik.o ./lib/Koloni.o ./lib/Oyun.o ./src/Test.c I have taken sample error – goOdyaga May 18 '23 at 17:18
  • Don't describe the code, edit your question to *show* the code. – dbush May 18 '23 at 17:20
  • 1
    You've defined a struct type called `struct URETIM`, then you also defined a variable of that type named `URETIM` in the header. You've done similar with the others structs. You probably don't want those variables. – dbush May 18 '23 at 18:11
  • thank you so much. I have give 2 day this error. ı really appreciate it :). – goOdyaga May 18 '23 at 18:25

0 Answers0