c - Cannot figure issue of "Undefined symbols for architecture x86_64" on Xcode -


i trying compile following code on xcode (it has been working fine on linux , trying generate mac os executables no success):

#ifndef _win32_winnt          #define _win32_winnt 0x0501   #endif                        #include <stdio.h> #ifdef win32 #include <tchar.h>  #endif #include <math.h> #include <malloc/malloc.h> #include "imgdec.h" #include "imgmacro.h" #include "tiffutils.h" #ifndef win32 #include "internal.h" #endif   #define m_pi 3.14159265358979323846 #define pi m_pi  int image_border = 10;   int usage(prog) char *prog; {   static char *helpmsg[] = {     "function: canny edge detection (undebugged)\n",     "options:\n",     "  -s (float): standard deviation gaussian kernel [default: 1.0] \     -t threshold [0 255]\n",     null   };   char **p=helpmsg;    fprintf(stderr,"usage: %s {options first} infile outfile\n",prog);   while (*p)     (void) fputs(*p++,stderr);   return(-1); }  int write_t1image(filename,image, ti, threshold) char *filename; fimage image; image *ti; // need header  float threshold; {   //file *stream;   int filetype();   image *tiffimage;   unsigned char *ptr;   unsigned char val;   short sval;     int x, y, yy;   fprintf(stderr,"image depth,etc. %d %d %d %d\n",                 (int) imagebpl(ti),imagedepth(ti),image.w,image.h);     tiffimage  = makeimage(                           imagebpl(ti),                            imagedepth(ti),                           image.w,                           image.h,                           imagexres(ti), // original resolution                            imageyres(ti),                           imageresunit(ti), //imageresunit                           imagephoto(ti) // photo interp                          );    if( !tiffimage)     {         fprintf(stderr,"write_timage(): null tiff image.\n");        return (int) null;    }      for( y = 0, ptr = imageptr(tiffimage), yy = 0; y < image.h; ++y, ++yy )            for( x = 0; x < image.w; ++x )            {   sval = (short)nint(image.ptr[y][x]);                 val = (byte) between(sval,0,255);                 if (val > threshold)                     ptr[x + y*image.w] = 255;                 else ptr[x + y*image.w] = 0;            }         writeimagetotiff( filename, tiffimage );     return 0; }  /* void canny_edge_detect(char *grey_filename,char *edge_filename,float sigma) {    char *c;    char *in, *out;    fimage image,edge,grad,angle; //   float sigma=1.0;    float threshold = -1.0; // no threshold     image *tiffimage;    image_border = (int)2*(sigma + 4);   // > 1/2 gaussian kernel size   // here differs original canny replacing read_tiffimage    // generic reader of qbic     if ((tiffimage = read_timage(grey_filename,&image)) == null) {      fprintf(stderr,"couldn't open file %s\n",grey_filename);      exit(-1);    }     edge.w = grad.w = angle.w = image.w;   edge.h = grad.h = angle.h = image.h;    alloc_fimage(&edge);   alloc_fimage(&grad);   alloc_fimage(&angle);    gaussfilt(image,sigma);    gradient(image,grad,angle);    non_maximum_suppression(edge,grad,angle);    fprintf(stderr, "writing image out threshold: %d\n",threshold);    write_t1image(edge_filename,edge, tiffimage, threshold);  } */     int non_maximum_suppression(edge,grad,angle) fimage edge,grad,angle; {    register float **e=edge.ptr,**g=grad.ptr,**a=angle.ptr;    int i,j,w=edge.w,h=edge.h;    float theta,alpha,g1,g2;     reflect(grad,1,1);    (j=0; j < h; j++)      (i=0; < w; i++) {        theta = a[j][i];        alpha = abs(tan(theta));        e[j][i] = 0.0;        if (theta <= -pi/4) {                /* use lower + lower right */          alpha = 1/alpha;          g1 = g[j-1][i] + alpha*(g[j-1][i+1] - g[j-1][i]);          if (g[j][i] < g1)            continue;          g2 = g[j+1][i] + alpha*(g[j+1][i-1] - g[j+1][i]);          if (g[j][i] < g2)            continue;          e[j][i] = g[j][i];     /* edge point strength */        } else if (theta > -pi/4 && theta <= 0.0) {  /* use right + lower right */          g1 = g[j][i+1] + alpha*(g[j-1][i+1] - g[j][i+1]);          if (g[j][i] < g1)            continue;          g2 = g[j][i-1] + alpha*(g[j+1][i-1] - g[j][i-1]);          if (g[j][i] < g2)            continue;          e[j][i] = g[j][i];     /* edge point strength */        } else if (theta > 0.0 && theta <= pi/4) {   /* use right + upper right */          g1 = g[j][i+1] + alpha*(g[j+1][i+1] - g[j][i+1]);          if (g[j][i] < g1)            continue;          g2 = g[j][i-1] + alpha*(g[j-1][i-1] - g[j][i-1]);          if (g[j][i] < g2)            continue;          e[j][i] = g[j][i];     /* edge point strength */        } else if (theta > pi/4) {          /* use upper + upper right */          alpha = 1/alpha;          g1 = g[j+1][i] + alpha*(g[j+1][i+1] - g[j+1][i]);          if (g[j][i] < g1)            continue;          g2 = g[j-1][i] + alpha*(g[j-1][i-1] - g[j-1][i]);          if (g[j][i] < g2)            continue;          e[j][i] = g[j][i];     /* edge point strength */        }       }    return 0; }  int gradient(image,grad,angle) fimage image,grad,angle; {    register float **p=image.ptr,**g=grad.ptr,**a=angle.ptr;    int i,j,w=image.w,h=image.h;    float dx,dy;     reflect(image,1,1);    (j=0; j < h; j++)      (i=0; < w; i++) {        dx = (p[j][i+1] - p[j][i-1])/2.0;        dy = (p[j+1][i] - p[j-1][i])/2.0;        g[j][i] = hypot(dx,dy);        if (dx != 0.0)          a[j][i] = atan(dy/dx);        else if (dy != 0)          a[j][i] = sign(pi/2,dy);        else          a[j][i] = 0.0;      }    return 0; }  #if 0  void matherr(struct _exception *exc) {    fprintf(stderr,"%s: ",exc->name);    switch (exc->type) {      case domain:        fprintf(stderr,"argument domain exception\n");        break;      case sing:        fprintf(stderr,"argument singularity\n");        break;      case overflow:        fprintf(stderr,"overflow range exception\n");        break;      case underflow:        fprintf(stderr,"underflow range exception\n");        break;      default:        fprintf(stderr,"unknown exception\n");    }    fprintf(stderr,"\tinput arguments: %f\t%f\n",exc->arg1,exc->arg2);    fprintf(stderr,"\treturn value: %f\n",exc->retval);    return(0); }  #endif  void get_gauss_kernel(gf,sigma) register filter *gf; float sigma; {    double sum,h,den=2*sigma*sigma;    register int j;     (j=1,sum=1.0; (h=exp(-j*j/den)) > 0.001; j++) {      sum += 2*h;    }    gf->taps = 2*j + 1;    gf->k = (float *) malloc(gf->taps*sizeof(*(gf->k)));    gf->k += (gf->taps-1)/2;    (j=0; j <= gf->taps/2; j++)      gf->k[j] = gf->k[-j] = exp(-j*j/den)/sum;    printf("number of taps =%d\n",gf->taps);    (j=0; j <= gf->taps/2; j++)      printf("g[%d] = %f\n",j,gf->k[j]);  }  int gaussfilt(image, sigma) fimage image; float sigma; {    filter gf;    fimage scr;     get_gauss_kernel(&gf,sigma);    scr.w = image.w;  scr.h = image.h;  alloc_fimage(&scr);    hor_reflect(image,gf.taps/2,1);    hor_sym_filter(image,scr,gf);    ver_reflect(scr,gf.taps/2,1);    ver_sym_filter(scr,image,gf);    free_fimage(scr);    free((gf.k-(gf.taps-1)/2));    return 0; }  // use stand alone version writes files out  #ifdef win32 int _tmain(int argc, _tchar* argv[]) #else int main (int argc, char *argv[]) #endif {    char *c,*prog=argv[0];    //char *in, *out;    fimage image,edge,grad,angle;    float sigma=1.0;    float threshold = -1.0; // no threshold     image *tiffimage;      while (--argc > 0 && (*++argv)[0] == '-')      (c = argv[0]+1; *c != '\0'; c++)        switch (*c) {          case 's':            --argc; sigma = (float) atof(*++argv);            {                printf ("sigma being set %f\n", sigma);            }            break;          case 't':            --argc; threshold = (float) atof(*++argv);               if( threshold < 0 || threshold > 255 )              {                  usage(prog);                   return -1; // exit               }              printf("thresold: %f\n",threshold);              break;          default:            fprintf(stderr,"%s: illegal option %c\n",prog,*c);          case 'h':            usage(prog);            break;        }    if (argc < 2)      usage(prog);     image_border = (int)2*(sigma + 4);   // > 1/2 gaussian kernel size   // here differs original canny replacing read_tiffimage   //  generic reader of qbic     if ((tiffimage = read_timage(*argv,&image)) == null) {      fprintf(stderr,"%s: couldn't open file %s\n",prog,*(argv+1));      exit(-1);    }     edge.w = grad.w = angle.w = image.w;   edge.h = grad.h = angle.h = image.h;    alloc_fimage(&edge);   alloc_fimage(&grad);   alloc_fimage(&angle);    gaussfilt(image, sigma);    gradient(image,grad,angle);    non_maximum_suppression(edge,grad,angle);    fprintf(stderr, "writing image out threshold: %f\n",threshold);    write_t1image(*++argv,edge, tiffimage, threshold);     return 0; } 

when trying compile, following errors (8 errors):

undefined symbols architecture x86_64:   "_tiffclose", referenced from:       _getimagefromtiff in tiffutils.o       _writeimagetotiff in tiffutils.o   "_tiffgetfield", referenced from:       _getimagefromtiff in tiffutils.o   "_tiffopen", referenced from:       _getimagefromtiff in tiffutils.o       _writeimagetotiff in tiffutils.o   "_tiffreadscanline", referenced from:       _getimagefromtiff in tiffutils.o   "_tiffscanlinesize", referenced from:       _getimagefromtiff in tiffutils.o   "_tiffsetfield", referenced from:       _writeimagetotiff in tiffutils.o   "_tiffwritescanline", referenced from:       _writeimagetotiff in tiffutils.o ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) 

also, here tiffutils.c code (not sure if related or not):

#include <malloc/malloc.h> #include <memory.h> #include "tiffwrap.h"   void free(void *ptr);  static unsigned char mask[8] = {128, 64, 32, 16, 8, 4, 2, 1};  image *getimagefromtiff(char *filename) {     image *iptr;    tiff *tif;    ttag_t imagelength,imagewidth;    unsigned char *buf;    unsigned int sample=0;    float imagexres,imageyres;    unsigned short imageresunit,photointerp, imagedepth;    long row,size;    int bpl;     iptr = (image *) malloc(sizeof(image));     tif = tiffopen(filename, "r");    tiffgetfield(tif, tifftag_imagelength, &imagelength);    bpl= tiffscanlinesize(tif);     bpl= 4*( (bpl+3)/4) ;    size=imagelength*bpl;    buf = (unsigned char *) calloc(size,1);    (row = 0; row < imagelength; row++)       tiffreadscanline(tif, buf+row*bpl, row, sample);     iptr->bpl = bpl;    iptr->pbuf = buf;    if (tiffgetfield(tif,tifftag_photometric, &photointerp))       iptr->photo = photointerp;    else       iptr->photo = undefined;    if( tiffgetfield(tif,tifftag_xresolution, &imagexres) )       iptr->xres = imagexres;    else       iptr->xres = undefined;    if ( tiffgetfield(tif,tifftag_yresolution, &imageyres) )       iptr->yres = imageyres;    else       iptr->yres = undefined;    if(tiffgetfield(tif,tifftag_resolutionunit, &imageresunit))       iptr->resunit = imageresunit;    else       iptr->resunit = undefined;    tiffgetfield(tif,tifftag_imagewidth, &imagewidth);    iptr->width = imagewidth;    tiffgetfield(tif,tifftag_bitspersample, &imagedepth);    iptr->depth = imagedepth;    iptr->length = imagelength;      tiffclose(tif);    return iptr; }        int writeimagetotiff(char *filename, image *pimage) {    tiff *tif;    //   char *buf;    long row;    //   int bpl;     unsigned int sample=0;      tif = tiffopen(filename, "w");    tiffsetfield(tif, tifftag_imagewidth, pimage->width);    tiffsetfield(tif, tifftag_imagelength,pimage->length);    tiffsetfield(tif, tifftag_bitspersample,pimage->depth);    //tiffsetfield(tif, tifftag_compression, compression_lzw);    tiffsetfield(tif, tifftag_compression, compression_none);    tiffsetfield(tif, tifftag_planarconfig,planarconfig_contig);    if(pimage->xres != undefined)       tiffsetfield(tif,tifftag_xresolution, pimage->xres);    if(pimage->yres != undefined)       tiffsetfield(tif,tifftag_yresolution, pimage->yres);    if(pimage->resunit != undefined)       tiffsetfield(tif,tifftag_resolutionunit, pimage->resunit);    if(pimage->photo != undefined)       tiffsetfield(tif,tifftag_photometric, pimage->photo);    for(row=0; row<pimage->length; ++row)            tiffwritescanline(tif, pimage->pbuf+row*pimage->bpl, row, sample);             tiffclose(tif);     return 1; }   image *makeimage(                         unsigned long bpl,                         unsigned short imagedepth,                         unsigned long imagewidth,                         unsigned long imagelength,                         float imagexres,                         float imageyres,                         unsigned short imageresunit,                         unsigned short photointerp                         ) {    image *iptr;    unsigned char *buf;    long size;     iptr = (image *) malloc(sizeof(image));     size=imagelength*bpl;    buf = (unsigned char *) calloc(size,1);     iptr->bpl = bpl;    iptr->pbuf = buf;    iptr->photo = photointerp;    iptr->xres = imagexres;    iptr->yres = imageyres;    iptr->resunit = imageresunit;    iptr->width = imagewidth;    iptr->depth = imagedepth;    iptr->length = imagelength;    return iptr; }  int close_image(image *pimage) {    free((char *)pimage->pbuf);    free((char *)pimage);    return 0; } /* x column y row */ int getpixel( int x, int y, image *i ) /* binary */      {  int bpl;         unsigned char val;          /*clip*/         if( x < 0 || y < 0                      || x >= imagewidth(i)                   || y >= imagelength(i) ) return 0; /* white */           bpl = imagebpl(i); /*bytes per line*/          val = i->pbuf[y*bpl + x/8];          return  (mask[x % 8] & val)>0?1:0;       }  void putpixel(int x, int y, unsigned char p, image *i )     {         int bpl, spot;          unsigned char val;         /*clip*/     //   if (p == 1)     //   fprintf(stderr,"in put pixel %d %d %d\n",x,y,p);         if( x < 0 || y < 0                      || x >= imagewidth(i)                   || y >= imagelength(i) ) return;            bpl = imagebpl(i); /*bytes per line*/          spot = y*bpl + x/8;          val = ((i->pbuf[spot] & mask[x % 8])>0)?1:0;                  p = (p > 0)? 1:0;            if( p  != val )                i->pbuf[spot] =  i->pbuf[spot] | mask[x % 8] ;         //  if (p ==1)          // fprintf(stderr,"after put pixel val , p %d %d %d\n",val,p,i->pbuf[spot]);         }  int  readtif ( image, rows, cols, hdr, file )     unsigned char *image;     int     *rows, *cols;     image   **hdr;     char    *file; {      image *image;     int width, height, bpl, depth;     int x, y;       /* image attributes */      image = getimagefromtiff(file);     width = imagewidth(image);     height = imagelength(image);     bpl = imagebpl(image);     depth = imagedepth(image);       if (depth == 1) {   /* binary image */      /* tiff convention represent white 1 , black 0 */      for( y = 0; y < height; y++ )         for( x = 0; x < width; x++ )         *(image ++) = (getpixel(x,y,image) == 0 ? 1 : 0);      }     else if (depth == 8) {  /* gray-level image */      for( y = 0; y < height; y++ )               for( x = 0; x < width; x++ )                 *( image + y*width + x) =   *(imageptr(image) + y* imagebpl (image) + x);         /*         memcpy (image + y*width,              imageptr(image) + y* imagebpl (image), width);          */      }     else {     fprintf (stderr, "readtif: sorry, non-standard depth\n");     return -1;     }      *rows = height;     *cols = width;     *hdr = image;      return depth; }   int  writetif ( image, rows, cols, hdr, file, bgcolor, fgcolor )     unsigned char *image;     int     rows, cols;     image   *hdr;     char    *file;     int     bgcolor, fgcolor; {      image *out;     unsigned char   *iptr;     int width, height, depth;     int x, y;       /* set image attributes */      width = cols;     height = rows;     depth = 1;       out = makeimage ((long) imagebpl(hdr), (short) depth, (long) width,               (long) height, imagexres(hdr), imageyres(hdr),               (unsigned short) imageresunit(hdr), (short) imagephoto(hdr));      /* tiff convention represent white 1 , black 0 */      iptr = image;      for( y = 0; y < height; y++ )     for( x = 0; x < width; x++ )         putpixel(x,y, (*iptr++ == bgcolor ? 1 : 0), out);      writeimagetotiff( file, out );      return 1; } 

what missing here? ideas?


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -