title: xcode does not compile c source
body: <p>I want to compile <a href="http://rosettacode.org/wiki/Matrix_multiplication" rel="nofollow noreferrer">sample c code from Rosettacode</a>. 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.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  /* 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-&gt;h = h, r-&gt;w = w;
      r-&gt;x = (double*)(r + 1);
      return r;
  }
  
  matrix mat_mul(matrix a, matrix b)
  {
      matrix r;
      double *p, *pa;
      int i, j;
      if (a-&gt;w != b-&gt;h) return 0;
  
      r = mat_new(a-&gt;h, b-&gt;w);
      p = r-&gt;x;
      for (pa = a-&gt;x, i = 0; i &lt; a-&gt;h; i++, pa += a-&gt;w)
          for (j = 0; j &lt; b-&gt;w; j++)
              *p++ = dot(pa, b-&gt;x + j, a-&gt;w, b-&gt;w);
      return r;
  }
  
  void mat_show(matrix a)
  {
      int i, j;
      double *p = a-&gt;x;
      for (i = 0; i &lt; a-&gt;h; i++, putchar('\n'))
          for (j = 0; j &lt; a-&gt;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(&amp;a, &amp;b);
  
      /* mat_show(&amp;a), mat_show(&amp;b); */
      mat_show(c);
      /* free(c) */
      return 0;
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/11696588/code-in-objective-c-2008-does-not-compile">I have found some pointers here</a> but I am getting compile errors and need more guidance.</p>
  
  <p>The xcode 4.5.2 project is currently for a Mac, but ultimately will be part of a project for iOS.</p>
  
  <p>The compile errors I get are as follows.</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_dot", referenced from:
        _mat_mul in code.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>I have placed the code in a file named <code>code.m</code> which has its own function <code>main()</code> and I wonder if that conflicts with the file <code>main.m's</code>  <code>main()</code> function, for example?</p>
  
  <p>Also, I would like to know how to actually see the resulting demo which I suppose requires using <code>NSLog</code> in the code.</p>
  
  <p>Btw, in the array db[], what does the data notation using <code>/</code> mean? Does it signify a rational fraction?</p>