我正在尝试按照此处的教程进行操作:
http://cocoadevcentral.com/articles/000081.php
当我到达“头文件”部分时,gcc test1.c -o test1
在 Mac OSX 命令行中运行后,我不断收到一条奇怪的错误消息:
Undefined symbols for architecture x86_64:
"_sum", referenced from:
_main in ccdZyc82.o
"_average", referenced from:
_main in ccdZyc82.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
数学函数.h:
int sum(int x, int y);
float average(float x, float y, float z);
数学函数.c:
int sum(int x, int y) {
return x + y;
}
float average(float x, float y, float z) {
return (x + y + z)/3;
}
最后,我的 test1.c:
#include <stdio.h>
#include "math_functions.h"
main() {
int thesum = sum(1, 2);
float ave = average(1.1, 2.21, 55.32);
printf("sum = %i\nave = %f\n(int)ave = %i\n", thesum, ave, (int)ave);
}
我似乎正确地遵循了一切,我不明白那个错误来自哪里。帮助?