我試圖按照這裏的教程:未知Objective-C的錯誤「適用於建築x86_64的未定義符號」,似乎一切都OK
http://cocoadevcentral.com/articles/000081.php
而且一旦我到了「頭文件」部分,我一直在Mac OSX上的命令行運行gcc test1.c -o test1
後得到一個奇怪的錯誤消息:
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
包括math_functions.h:
int sum(int x, int y);
float average(float x, float y, float z);
math_functions.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);
}
我似乎已正確執行了一切,我不明白的地方是錯誤的來源。幫幫我?
http://stackoverflow.com/questions/1754460/apples-gcc-whats-the-difference-between-arch-i386-and- m32 希望這會有所幫助。 – AechoLiu 2012-07-16 09:14:48