Ich habe dieses folgende einfache Programm Ich versuche, in Linux Ubuntu zu kompilieren.In C-Programmierung, was ist `undefined reference`error, wenn kompilieren?
Main.c
:
#include <stdio.h>
#include "Person.h"
int main()
{
struct Person1 p1 = Person1_Constructor(10, 1000);
}
Person.c
:
#include <stdio.h>
#include "Person.h"
struct Person1 Person1_Constructor(const int age, const int salary)
{
struct Person1 p;
p.age = age;
p.salary = salary;
return p;
};
Person.h
:
struct Person1
{
int age, salary;
};
struct Person1 Person1_Constructor(const int age, const int salary);
Warum bekomme ich folgende Fehler?
/tmp/ccCGDJ1k.o: In function `main':
Main.c:(.text+0x2a): undefined reference to `Person1_Constructor'
collect2: error: ld returned 1 exit status
Ich verwende gcc Main.c -o Main
zu kompilieren.
@ Satya uh, warum? Ich habe eine 'Person.c' und eine' Person.h' was ist damit falsch? – dimitris93
gcc zwei .c Dateien zusammen – user3528438