You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\EDGARG~1\AppData\Local\Temp\cciw4GDE.o: in function main': C:/Users/Edgar Gomez/Desktop/relearnC/main.c:7:(.text+0x22): undefined reference to createPerson'
collect2.exe: error: ld returned 1 exit status
El proceso del terminal "C:\Program Files\CodeBlocks\MinGW\bin\gcc.EXE '-Wall', '-Wextra', '-g3', 'c:\Users\Edgar Gomez\Desktop\relearnC\main.c', '-o', 'c:\Users\Edgar Gomez\Desktop\relearnC\output\main.exe'" finalizó con el código de salida 1.
Las tareas reutilizarán el terminal, presione cualquier tecla para cerrarlo.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I am doing a simple program but i cant compile it since i divide the code in multiple files but the compiler command only include de main.c file
Solution sturcture
|__business
| |__person.c
| |__person.h
|__main.c
files
mian.c
`#include <stdio.h>
#include <stdlib.h>
#include "./business/Person.h"
int main(void)
{
Person edgar = createPerson("Jhon Doe", 35);
edgar.resume(&edgar);
}`
person.h
`#ifndef PERSON_H
#define PERSON_H
typedef struct Person
{
char name[50];
int age;
char *(*resume)(struct Person *p);
void (*release)(struct Person *p);
} Person;
Person createPerson(char *name, int age);
#endif // PERSON_H`
person.c
`#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Person.h"
char *resume(struct Person *p)
{
const int bufferSize = 100;
char *buffer = malloc(bufferSize * sizeof(char));
snprintf(buffer, bufferSize, "Name: %s, Age: %d", p->name, p->age);
return buffer;
}
void release(struct Person *p)
{
free(p->name);
}
Person createPerson(char *name, int age)
{
Person p;
strcpy(p.name, name);
p.age = age;
p.resume = resume;
p.release = release;
return p;
}`
here is the output
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\EDGARG~1\AppData\Local\Temp\cciw4GDE.o: in function
main': C:/Users/Edgar Gomez/Desktop/relearnC/main.c:7:(.text+0x22): undefined reference to
createPerson'collect2.exe: error: ld returned 1 exit status
Beta Was this translation helpful? Give feedback.
All reactions