我有下面這個簡單的程序,我想在linux ubuntu中編譯。在C編程中,編譯時什麼是`undefined reference`error?
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);
爲什麼我得到以下錯誤?
/tmp/ccCGDJ1k.o: In function `main':
Main.c:(.text+0x2a): undefined reference to `Person1_Constructor'
collect2: error: ld returned 1 exit status
我使用gcc Main.c -o Main
進行編譯。
@Satya呃,爲什麼?我有一個'Person.c'和一個'Person.h'最近怎麼了? – dimitris93
gcc兩個.c文件在一起 – user3528438