X code不编译C源代码 [英] xcode does not compile c source

查看:152
本文介绍了X code不编译C源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从编译罗塞塔code 样品C code 。我想从我的iOS项目适应做一个简单的矩阵乘法,其中2矩阵之一就是一排,而不是行和列。罗塞塔code是如下:

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;/ *与数据结构自包含的。元素在第i行和colĴ
   为x [我* W + J]。更多的往往不是,但是,你可能希望
   重新present矩阵一些其他的方式* /
typedef结构{INT小时,瓦;双* X;} matrix_t,*矩阵;内嵌双点(双*一,双* B,INT LEN,INT步)
{
    双R = 0;
    而(len--){
        R + = * a ++ * * B;
        B + =步骤;
    }
    返回ř;
}矩阵mat_new(INT小时,INT W)
{
    矩阵R =的malloc(sizeof的(矩阵)+的sizeof(双)* W * H);
    R-> H = H,R 34 GT; W =瓦;
    R-> X =(双*)(R + 1);
    返回ř;
}矩阵mat_mul(矩阵,矩阵B)
{
    矩阵R;
    双* P * PA;
    INT I,J;
    如果(A-> W = B->!h)返回0;    R = mat_new(A-> H,B> W)
    p值= R-&X的催化剂;
    对于(PA = A-> X,I = 0; I< A-> H,我++,PA + = A-> W)
        为(J = 0; J< B->瓦; J ++)
            * P + =点(PA,B> X + J,A-> W,B-> W)
    返回ř;
}无效mat_show(矩阵)
{
    INT I,J;
    双* P = A-> X;
    对于(i = 0; I< A-> H,我++的putchar('\\ n'))
        为(J = 0; J< A->瓦; J ++)
            的printf(\\ t%7.3f,* P ++);
    的putchar('\\ n');
}诠释的main()
{
    双哒[] = {1,1,1,1,
            2,4,8,16,
            3,9,27,81,
            4,16,64,256};
    双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}哒,B = {4,3}分贝;
    矩阵C = mat_mul(安培;一,和b);    / * mat_show(&放大器;一个),mat_show(和b); * /
    mat_show(C);
    / *免费的(C)* /
    返回0;
}

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

的X code 4.5.2项目目前在Mac,但最终将是iOS版项目的一部分。

是编译错误,我得到如下:

 适用于建筑x86_64的未定义符号:
  _dot,从引用:
      _mat_mul在code.o
LD:符号(S)未找到x86_64的架构

我已经放在code名为 $ C $厘米 A文件,它有它自己的功能的main(),我不知道这是否与该文件 main.m文件的 的main()功能相冲突,例如<? / p>

另外,我想知道如何真正看到的结果演示,我想要求使用的NSLog 在code。

顺便说一句,数组DB []中,什么是使用数据符号 / 是什么意思?这是否意味着一个合理的分数?


解决方案

添加关键字静态在一个内联函数声明前,编译器应该是更快乐。

I want to compile sample c code from Rosettacode. I want to adapt it from my iOS project to do a simple matrix multiply where one of the 2 matrices is just a row, not a row and a column. The Rosettacode is as follows.

#include <stdio.h>
#include <stdlib.h>

/* 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 < a->h; i++, pa += a->w)
        for (j = 0; j < b->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 < a->h; i++, putchar('\n'))
        for (j = 0; j < a->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;
}

I have found some pointers here but I am getting compile errors and need more guidance.

The xcode 4.5.2 project is currently for a Mac, but ultimately will be part of a project for iOS.

The compile errors I get are as follows.

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

I have placed the code in a file named code.m which has its own function main() and I wonder if that conflicts with the file main.m's main() function, for example?

Also, I would like to know how to actually see the resulting demo which I suppose requires using NSLog in the code.

Btw, in the array db[], what does the data notation using / mean? Does it signify a rational fraction?

解决方案

Add the keyword static in front of an inline function declaration and the compiler should be much happier.

这篇关于X code不编译C源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆