xcode不编译c源代码

我想从Rosettacode编译示例c代码 。 我想从我的iOS项目中调整它来做一个简单的矩阵乘法,其中2个矩阵中的一个只是一行,而不是一行和一列。 Rosettacode如下。

#include  #include  /* Make the data structure self-contained. Element at row i and col j is x[i * w + j]. More often than not, though, you might want to represent a matrix some other way */ typedef struct { int h, w; double *x;} matrix_t, *matrix; inline double dot(double *a, double *b, int len, int step) { double r = 0; while (len--) { r += *a++ * *b; b += step; } return r; } matrix mat_new(int h, int w) { matrix r = malloc(sizeof(matrix) + sizeof(double) * w * h); r->h = h, r->w = w; r->x = (double*)(r + 1); return r; } matrix mat_mul(matrix a, matrix b) { matrix r; double *p, *pa; int i, j; if (a->w != b->h) return 0; r = mat_new(a->h, b->w); p = r->x; for (pa = a->x, i = 0; i h; i++, pa += a->w) for (j = 0; j w; j++) *p++ = dot(pa, b->x + j, a->w, b->w); return r; } void mat_show(matrix a) { int i, j; double *p = a->x; for (i = 0; i h; i++, putchar('\n')) for (j = 0; j w; j++) printf("\t%7.3f", *p++); putchar('\n'); } int main() { double da[] = { 1, 1, 1, 1, 2, 4, 8, 16, 3, 9, 27, 81, 4,16, 64, 256 }; double db[] = { 4.0, -3.0, 4.0/3, -13.0/3, 19.0/4, -7.0/3, 3.0/2, -2.0, 7.0/6, -1.0/6, 1.0/4, -1.0/6}; matrix_t a = { 4, 4, da }, b = { 4, 3, db }; matrix c = mat_mul(&a, &b); /* mat_show(&a), mat_show(&b); */ mat_show(c); /* free(c) */ return 0; } 

我在这里找到了一些指示,但我收到了编译错误,需要更多的指导。

xcode 4.5.2项目目前适用于Mac,但最终将成为iOS项目的一部分。

我得到的编译错误如下。

 Undefined symbols for architecture x86_64: "_dot", referenced from: _mat_mul in code.o ld: symbol(s) not found for architecture x86_64 

我已经将代码放在一个名为code.m的文件中,该文件有自己的函数main() ,我想知道它是否与文件main.m's main()函数冲突,例如?

另外,我想知道如何实际看到生成的演示,我想在代码中使用NSLog

顺便说一句,在数组db []中,使用/表示数据符号是什么意思? 它是否意味着合理的分数?

在内联函数声明前添加关键字static ,编译器应该更快乐。