只是一個簡單的程序,但我不斷收到此編譯器錯誤。我使用MinGW編譯器。C錯誤:未定義的函數引用,但它被定義爲
這裏的頭文件,point.h:
//type for a Cartesian point
typedef struct {
double x;
double y;
} Point;
Point create(double x, double y);
Point midpoint(Point p, Point q);
而這裏的point.c:
//This is the implementation of the point type
#include "point.h"
int main() {
return 0;
}
Point create(double x, double y) {
Point p;
p.x = x;
p.y = y;
return p;
}
Point midpoint(Point p, Point q) {
Point mid;
mid.x = (p.x + q.x)/2;
mid.y = (p.y + q.y)/2;
return mid;
}
這裏的地方編譯器問題進來我不斷收到:
testpoint.c: undefined reference to 'create(double x, double y)'
雖然它是在point.c中定義的。
這就是所謂的testpoint.c一個單獨的文件:
#include "point.h"
#include <assert.h>
#include <stdio.h>
int main() {
double x = 1;
double y = 1;
Point p = create(x, y);
assert(p.x == 1);
return 0;
}
我在一個無所適從的問題可能是。
你得到任何其他消息? – JaredPar 2011-04-05 22:20:22
你可以發佈你的makefile嗎?另外,您定義了2個主要功能,這不可能是好的。 – George 2011-04-05 22:20:34
可能是對main()進行重新定義,它是程序的入口點。擺脫'point.c'中的那一個 – RageD 2011-04-05 22:25:49