0

so i'm creating a "game" in c, where the user make choices and the content showed to him depends on his choice. So i created different files with multiple functions, functions that i included in header files, header files that i finally included in the other files where i'm calling these function. Here is an example with the type function that write caracters one by one. the first file is step0.c, where i use type function, and where the compiler tell me that the function "type" is undefined here is the error message if it can help :

step0.o: In function eventS0': step0.c:(.text+0x10e): undefined reference to type' step0.o:step0.c:(.text+0x12b): more undefined references to type' follow step0.o: In function eventS0': step0.c:(.text+0x1e2): undefined reference to updateStats' step0.c:(.text+0x25b): undefined reference to printStats' step0.c:(.text+0x26b): undefined reference to type' step0.o: In function choixS0': step0.c:(.text+0x2c9): undefined reference to type' step0.c:(.text+0x2d5): undefined reference to type' step0.c:(.text+0x2e1): undefined reference to type' step0.o: In function descS0': step0.c:(.text+0x3a7): undefined reference to type' step0.o:step0.c:(.text+0x3b3): more undefined references to type' follow collect2: error: ld returned 1 exit status

step0.c :
#include "../system/type.h"
#include "../item/itemALL.h"
#include "step0.h"
#include "../system/stats.h"

int eventS0(struct ch player2, int i) { //event type : shop
  // elipse entrainement, resort avec de meilleurs stats et du gold 
  char trainer[10];
  char object[20];
  int itemChoix = 0;
  if (i == 1) {
    strcpy(trainer, "Ragnar");
    strcpy(object, "Bouclier de tank");
    itemChoix = 3;
  }
  else if(i == 2) {
    strcpy(trainer, "Heuss");
    strcpy(object, "Epee de chevalier");
    itemChoix = 2;
  }
  else if (i == 3) {
    strcpy(trainer, "Harry");
    strcpy(object, "Livre de sorcier");
      itemChoix = 1;;
  }
  else {
    printf("error : input invalid ! exiting...\n\n");
    exit(1);
  }
  type("\033[31m.......\033[0m");
  printf("\033[2J\033[1;1H");
    type("\033[31m.......\033[0m");
  printf("\033[2J\033[1;1H");
    type("\033[31m.......\033[0m");
  printf("\033[2J\033[1;1H");
    type("\033[31m.......\033[0m");
  printf("\033[2J\033[1;1H");
  type("Votre entrainement est enfin termine !\n");
  type("Vous etes pret a partir au combat, mais avant cela, vous allez recevoir un cadeau de la part de ");
  printf(" %s\n", trainer);
  sleep(2);
  type("Felicitation, vous venez de recevoir ");
  printf(" %s\n", object);
  updateStats(&player2, itemChoix);
  printStats(player2);
  type("Assez discute, vous avez un monde a sauver !\n\n");
  sleep(1);
  printf("\033[2J\033[1;1H");
  return i;
}

int choixS0(struct ch player2) { // NE PAS METTRE D4ACCENT DANS TYPE SINON BUG
  int i = 0;
  type("Neanmoins, votre peuple est sous l'assault de monstres cruels, et vous n'aurez le temps de vous former qu'une fois\n");
  type("N'oubliez pas que chaque specialisation de votre personage vous apportera une experience de jeu differente !\n");
  type("(1) choisir Ragnar le \033[31mgolem\033[0m\n(2) choisir Heuss le \033[31mchevalier\033[0m\n(3) choisir Harry le \033[31msorcier\033[0m\n");
  scanf("%d", &i);
  player2.class = i;
  return eventS0(player2, i);
}

here is the type.c file where the function is defined :

type.c :
#include "type.h"
void type(char *input) { // fonction pour simuler lécriture du texte dans le terminal
  int size = strlen(input);
  struct timespec pause = {0, 100000000};
  for (int i = 0; i < size; i++) {
    putchar(input[i]);
    fflush(stdout);
    nanosleep(&pause, NULL); //délai d'écriture en micro seconde
  }
}                                                                                                                                                                                                                                        

and here is the type.h file :

type.h :
#define TYPE_H

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

extern void type(char *input);                           

i know this is a lot to look out but i wanted to give as much context as possible. Note that other functions as updateStats, printStats ect are not working either and have the same structure, and that i get this error in all my files. finally i want to provide you my makefile, wich might be my problem because its my first ( i searched everywhere for help but didnt find it ) :

makefile :
CC=gcc
CFLAGS = -Wall -Wextra -Werror -I/ncurses/include/ncurses
LDFLAGS = -lncurses

SSYSTEM= $(wildcard system/*.c)
SPROFILE2= $(wildcard profile/*.c)
SSTEP1= $(wildcard step/mage/*.c)
SSTEP2= $(wildcard step/chevalier/*.c)
SSTEP3= $(wildcard step/golem/*.c)
SSAVE= $(wildcard save/*.c)
SITEM= $(wildcard save/*.c)

#SPROFILE= $(filter-out player.c,$(SPROFILE2))

#manual obj files : endLose.c endWin.c step0.c

OSYSTEM= $(patsubst %.c,%.o,$(SSYSTEM))
OPROFILE= $(patsubst %.c,%.o,$(SPROFILE))
OSTEP1= $(patsubst %.c,%.o,$(SSTEP1))
OSTEP2= $(patsubst %.c,%.o,$(SSTEP2))
OSTEP3= $(patsubst %.c,%.o,$(SSTEP3))
OSAVE= $(patsubst %.c,%.o,$(SSAVE))
OITEM= $(patsubst %.c,%.o,$(SiTIEM))

ISYSTEM= system/type.h system/stats.h item/itemALL.h profile/champ.h
IITEM= item/itemALL.h
IMONSTER = profile/monsterALL.h
ISTEP1 = step/mage/stepALL.h system/type.h system/stats.h
IPROFILE = profile/monsterALL.h

all : adventure

$(OSYSTEM) : $(SSYSTEM) $(ISYSTEM)
        $(CC) -c $< -o $@

player.o : profile/player.c profile/champ.h
        $(CC) -c $< -o $@

step0.o : step/step0.c system/stats.h item/itemALL.h step/step0.h system/type.h
        $(CC) -c $< -o $@

$(OMONSTER) : $(SMONSTER) $(IMONSTER)
        $(CC) -c $< -o $@

$(OITEM) : $(SITEM) $(IITEM)
        $(CC) -c $< -o $@


$(OSTEP1) : $(SSTEP1) system/type.c $(ISTEP1)
        $(CC) -c $< -o $@

main.o : main.c system/start.h system/type.h step/mage/stepALL.h step/step0.h
        $(CC) -c $< -o $@

adventure : main.o $(OSTEP1) $(OSYSTEM) $(OMONSTER) $(OITEM) step0.o player.o
        $(CC) $^ -o $@

clean :
        rm -f *.o

i tried adding the source .c files to the makefile dependency as chatgpt told me, but didnt work. i tried modifying the organization of my header and source in all way possible so i dont think its the problem.

Naël
  • 1
  • 1
  • 2
    `i tried adding the source .c files to the makefile dependency as chatgpt told me` ChatGPT? DId ChatGPT write all this? If so there's no guarantee that it will or can work at all. As far as if ChatGPT can solve the issue, again, there's no guarantee its solution will work. If you are using ChatGPT to write code that you neither understand nor know how to fix, then that's basically useless. It's not our job to fix the output generated by a chatbot. We want to help humans fix code that they wrote themselves. So, please clarify what *you* wrote, and what *you* understand about it. – Random Davis May 12 '23 at 17:09
  • Where is "type.c" located in the directory tree? Where are the `updateStats` and `printStats` functions defined? – Ian Abbott May 12 '23 at 17:27
  • 1
    Please see [Temporary policy: ChatGPT is banned](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned): *the ban applies to all content on Stack Overflow, except each user's profile content*. – Weather Vane May 12 '23 at 17:27
  • so. Where do you see that gpt writed this ? i writed this. i explicitely told that i tried to do something chatgpt told me to resolve the issue, but it didnt work. I understand what i wrote because I wrote it, what i dont understand is why my functions are delcared as undefined even tho they are. – Naël May 12 '23 at 19:49
  • to awnser you Ian, my type.c and type.h files are located in root/system/, and my main.c file is located in root/ . – Naël May 12 '23 at 19:52

0 Answers0