Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Code: cc main.o image.o camera.o -o camapp main.o(.text+0x55): In function `main': : undefined reference to `captureImage' collect2: ld returned 1 exit status Why could I obtain that message error when ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    16

    Undefined reference


    Code:
     cc main.o image.o camera.o -o camapp
    main.o(.text+0x55): In function `main':
    : undefined reference to `captureImage'
    collect2: ld returned 1 exit status
    Why could I obtain that message error when I'm trying linking my program ? The declaration of that function I've coded seems to be written without typing mistakes. I also check the order I present object files to the linker, but even in the other side, it changes nothing to the result.

    I could put some parts of my program here if you think it would be easier to help me, but on the other side, I don't want making that message too long.

    The structure of the application looks like that:

    camera.c wich define captureImage, image.c convert to PPM format and main.c calling captureImage

    camera.h
    Code:
    #ifndef CAMERA_H
    #define CAMERA_H
    
    #define WIDTH 352
    #define HEIGHT 288
    #define PALETTE VIDEO_PALETTE_RGB24;
    
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/ioctl.h>
    #include <sys/mman.h>
    #include <linux/videodev.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <errno.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void openCam&#40;void&#41;;
    void closeCam&#40;void&#41;;
    void printCap&#40;void&#41;;
    void frambufDetect&#40;void&#41;;
    void setWin&#40;void&#41;;
    void setImage&#40;int hue, int colour, int contrast, int brightness, int depth&#41;;
    void set_buffer&#40;void&#41;;
    void captureImage&#40;void &#40;*ptrfonction&#41; &#40;unsigned char*&#41;, int rep&#41;;
    ...
    camera.c
    Code:
    ...
    void captureImage&#40;void &#40;*ptrfonction&#41; &#40;unsigned char*&#41;, int rep&#41;
    &#123;
    int i, nbcapture=1;
    image=0;
    
    while&#40;nbcapture<=rep&#41;
            &#123;
            while&#40;i<0&#41;&#123; /*Tant qu'on obtient une erreur, l'appel doit etre repete. */
                        /*On verifie que la fonction a reussi et qu'il n'y a pas eu de signals qui ont interrompu l'appel.*/
            i=ioctl&#40;descrpFichier, VIDIOCSYNC, &image&#41;;
            if&#40;i < 0 || errno == EINTR&#41;
            &#123;
            if&#40;i<0&#41;
                    &#123;
                    perror&#40;"VIDIOCSYNC"&#41;;
                    printf&#40;"Le programme doit quitter\n\a"&#41;;
                    exit&#40;-1&#41;;
                    &#125;
            continue;
            &#125;
            break; /*La sync. s'est bien deroule. On sort de la boucle*/
            &#125;
    
    posImg=ptr+mbuf.offsets&#91;image&#93;;
    ...
    main.c
    Code:
    #include "camera.h"
    extern void extractPix&#40;unsigned char* imgbuffer&#41;;
    int main&#40;void&#41;
    &#123;
    openCam&#40;&#41;;
    printCap&#40;&#41;;
    frambufDetect&#40;&#41;;
    setWin&#40;&#41;;
    setImage&#40;128,128,128,128,24&#41;;
    set_buffer&#40;&#41;;
    captureImage&#40;&extractPix, 2&#41;;
    closeCam&#40;&#41;;
    return 0;
    &#125;
    *Note that extractPix function is defined into another file not shown here because it doesn't refer to any functions taken elsewhere.

    Thanks helping me. The project is progressing...

  2. #2
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Would it help if you compiled sources indstead of object files? Perhaps they are unsynchronized...
    Code:
    cc main.c image.c camera.c -o camapp
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  3. #3
    Just Joined!
    Join Date
    Jun 2004
    Posts
    16
    Unfortunately, it gives the same result...

  4. #4
    Just Joined!
    Join Date
    Nov 2004
    Posts
    22
    One thing I can think of is that the linker is unable to define that extern function you have. Otherwise it seems correct.

    Try provide a phony body to that extern function you have declared at top of your mainfile and try to link again or provide the objectfile where that function is defined with the linking command.

    Where is the: extern void extractPix(unsigned char* imgbuffer); defined?

    Just a thought.
    Good luck

  5. #5
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    Maybe if you gave us a link to your code, we might be able to help..
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  6. #6
    Just Joined!
    Join Date
    Jun 2004
    Posts
    16
    Quote Originally Posted by Ancoblanco
    [...]
    Where is the: extern void extractPix(unsigned char* imgbuffer); defined?
    This function is defined in image.c


    Quote Originally Posted by kyku
    Maybe if you gave us a link to your code, we might be able to help..
    That's what I'm going to do... Here's the complete code:

    http://machivi.ma.cx/pierre-luc/camapp/

    I didn't gave the code source because I thought that nobody could take time to analyze it. I appreciate your support.

  7. #7
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    I've got your error, it's mainly because of the crappy coding style you use (sorry). You simply misplaced {'s and captureImage got itself swallowed inside of set_buffer as an internal procedure. Put a } before captureImage and remove one } at the end of file. And, as an advice from an (not so) old programmer, equip yourself with an intending editor Good night...
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  8. #8
    Linux User
    Join Date
    Jul 2004
    Location
    Poland
    Posts
    368
    There are several more errors in your code, but I'm sure you'll be able to fix them. Remember to use gcc's -Wall flag for better error reporting and discovery.
    "I don't know what I'm running from
    And I don't know where I'm running to
    There's something deep and strange inside of me I see"

  9. #9
    Just Joined!
    Join Date
    Nov 2004
    Posts
    22
    Hi. Your problem is in the camera.c file... you've missused the brackets {} in a couple of places (or just missed to close one function just above the captureImage() function. I guess that it'll be declared as an local function instead, just for use in set_buffer() function that was above, or something.

    I'll list the whole code here so that you can compare it with the faulty one
    I apologize for the size of this post.

    Code:
    #include "camera.h"
    
    /*Ouverture de la camera*/
    void openCam&#40;void&#41;
    &#123;
    devicename="/dev/video0";
    descrpFichier=open&#40;devicename, O_RDWR&#41;;
    if&#40;descrpFichier < 0&#41; 
    	&#123;
    	printf&#40;"\aAucun peripherique detecte\n"&#41;;
    	printf&#40;"Verifiez les droits d'acces a /dev/video0\n"&#41;;
    	exit&#40;-1&#41;;
    	&#125;
    &#125;
    
    /*Fermeture de la camera*/
    void closeCam&#40;void&#41;
    &#123;
    close&#40;descrpFichier&#41;;
    munmap&#40;ptr, mbuf.size&#41;;
    &#125;
    
    /*Informations sur les capacites du peripherique*/
    void printCap&#40;void&#41;
    &#123;
    if&#40;ioctl&#40;descrpFichier, VIDIOCGCAP, &vidcap&#41; < 0&#41; exit -1;
    if&#40;ioctl&#40;descrpFichier, VIDIOCGWIN, &fenetre&#41; < 0&#41; exit -1;
    if&#40;ioctl&#40;descrpFichier, VIDIOCGPICT, &image&#41; < 0&#41; exit -1;
    
    printf&#40;"-------------------------------------------------------\n"&#41;;
    printf&#40;"Nom&#58; %s\n", vidcap.name&#41;;
            if&#40;!&#40;vidcap.type && VID_TYPE_CAPTURE&#41;&#41;
            &#123;
            printf&#40;"Le peripherique detecte ne supporte pas la capture\n"&#41;;
            exit&#40;-1&#41;;
            &#125;
    printf&#40;"Type&#58; Camera\n", vidcap.type&#41;;
    printf&#40;"Audio&#58; %d\n", vidcap.audios&#41;;
    printf&#40;"Largeur max.&#58; %d\n", vidcap.maxwidth&#41;;
    printf&#40;"Longueur max.&#58; %d\n", vidcap.maxheight&#41;;
    printf&#40;"Largeur min.&#58; %d\n", vidcap.minwidth&#41;;
    printf&#40;"Longueur min.&#58; %d\n", vidcap.minheight&#41;;
    printf&#40;"-------------------------------------------------------\n"&#41;;
    printf&#40;"\n\n"&#41;;
    &#125;
    
    /*Detection d'un framebuffer*/
    void frambufDetect&#40;void&#41;
    &#123;
    printf&#40;"-------------------------------------------------------\n"&#41;;
    if&#40;ioctl&#40;descrpFichier, VIDIOCSFBUF, &buffer&#41; <0&#41;
    &#123;
    perror&#40;"VIDIOCSBUF"&#41;;
    printf&#40;"La carte de capture ne supporte pas l'ecriture directe\nau framebuffer\n"&#41;;
    &#125;
    if&#40;ioctl&#40;descrpFichier, VIDIOCGFBUF, &buffer&#41; <0&#41;perror&#40;"VIDIOCGFBUF"&#41;;
    printf&#40;"Adresse&#58; %d\n", buffer.base&#41;;
    printf&#40;"Longueur&#58; %d\n", buffer.height&#41;;
    printf&#40;"Largeur&#58; %d\n", buffer.width&#41;;
    printf&#40;"Profondeur&#58; %d\n", buffer.depth&#41;;
    printf&#40;"Octets par ligne&#58; %d\n", buffer.bytesperline&#41;;
    printf&#40;"-------------------------------------------------------\n"&#41;;
    &#125;
    
    /*Definition de la fenetre de capture*/
    void setWin&#40;void&#41;
    &#123;
    fenetre.x = 0;
    fenetre.y = 0;
    fenetre.width = WIDTH;
    fenetre.height = HEIGHT;
    fenetre.clipcount = 0;
    fenetre.chromakey = 0;
    fenetre.clipcount = 0;
    
    if&#40;ioctl&#40;descrpFichier, VIDIOCSWIN, &fenetre&#41; < 0&#41; 
    	&#123;
    	perror&#40;"VIDIOCSWIN"&#41;; 
    	exit&#40;-1&#41;;
    	&#125;
    &#125;
    
    /*Definition des proprietes de l'image*/
    void setImage&#40;int hue, int colour, int contrast, int brightness, int depth&#41;
    &#123;
    image.hue = hue;
    image.colour = colour;
    image.contrast = contrast;
    image.brightness = brightness;
    image.depth = depth;
    image.palette = PALETTE;
    
    if&#40;ioctl&#40;descrpFichier, VIDIOCSPICT, &image&#41;<0&#41;
    	&#123;
    	perror&#40;"VIDIOCSPICT"&#41;;
    	exit -1;
    	&#125;
    &#125;
    
    /*On demande un buffer*/
    void set_buffer&#40;void&#41;
    &#123;
      int image;
    
      if&#40;ioctl&#40;descrpFichier, VIDIOCGMBUF, &mbuf&#41; < 0&#41;
        &#123;
          printf&#40;"Impossible d'obtenir un buffer\n"&#41;;
          exit -1;
        &#125;
      printf&#40;"\n\n-------------------------------------------------------\n"&#41;;
      printf&#40;"Memoire tampon\n"&#41;;
      printf&#40;"Taille&#58; %d\n", mbuf.size&#41;;
      printf&#40;"Images&#58; %d\n", mbuf.frames&#41;;
      printf&#40;"Coordonnes&#58; %d\n", mbuf.offsets&#41;;
      printf&#40;"-------------------------------------------------------\n"&#41;;
      /*Un espace memoire est alloue selon la taille totale de tous les buffers disponnibles*/
      ptr = &#40;unsigned char*&#41; mmap&#40;0, mbuf.size, PROT_READ|PROT_WRITE, MAP_SHARED,descrpFichier, 0&#41;;
    
      if&#40;ptr==&#40;unsigned char*&#41; -1&#41;
        &#123;
          perror&#40;"mmap&#40;&#41;"&#41;;
          exit&#40;-1&#41;;
        &#125;	
      /*Les demandes de captures sont mises dans la file d'attente du buffer*/
      mapbuf.height = HEIGHT ;
      mapbuf.width = WIDTH;
      mapbuf.format = PALETTE;
    
      /*On boucle les demandes de captures selon le nombre de frames definies dans mbuf*/
      for&#40;image=0; image<mbuf.frames; image++&#41;
        &#123;
          mapbuf.frame = image;
          if&#40;ioctl&#40;descrpFichier, VIDIOCMCAPTURE, &mapbuf&#41;&#41;
    	&#123;
    	  perror&#40;"VIDIOCMCAPTURE"&#41;;
    	  exit&#40;-1&#41;;
    	&#125;
        &#125;
    &#125;
    
    /*La fonction de capture recoit en argument l'adresse de la fonction a appeler*/
    void captureImage&#40;void &#40;*ptrfonction&#41; &#40;unsigned char*&#41;, int rep&#41;
    &#123;
      int i, nbcapture=1;
      int image=0;
    
      while&#40;nbcapture<=rep&#41;
        &#123;
          while&#40;i<0&#41;&#123; /*Tant qu'on obtient une erreur, l'appel doit etre repete. */
    	/*On verifie que la fonction a reussi et qu'il n'y a pas eu de signals qui ont interrompu l'appel.*/
    	i=ioctl&#40;descrpFichier, VIDIOCSYNC, &image&#41;;
    	if&#40;i < 0 || errno == EINTR&#41;
    	  &#123;
    	    if&#40;i<0&#41;
    	      &#123;
    		perror&#40;"VIDIOCSYNC"&#41;;
    		printf&#40;"Le programme doit quitter\n\a"&#41;;
    		exit&#40;-1&#41;;
    	      &#125;
    	    continue;
    	  &#125;
    	break; /*La sync. s'est bien deroule. On sort de la boucle*/
          &#125;
    	
          posImg=ptr+mbuf.offsets&#91;image&#93;;
          /*La fonction de traitement peut maintenant etre appellee avec posImg comme argument*/
          ptrfonction&#40;posImg&#41;;
          /*On remet le buffer a la disposition du driver*/
     
          mapbuf.frame = image;
          if&#40;ioctl&#40;descrpFichier, VIDIOCMCAPTURE, &mapbuf&#41;<0&#41;
    	&#123;
    	  perror&#40;"VIDIOCMCAPTURE"&#41;;
    	  printf&#40;"L'application doit quitter\n\a"&#41;;
    	  closeCam&#40;&#41;;
    	  exit&#40;-1&#41;;
    	&#125;
          image++;
    
          if&#40;image>mbuf.frames&#41;image=0;
    
          if&#40;1!=rep&#41; nbcapture++;/*Si nbcapture est different de 1, on n'incremente pas on boucle a l'infini*/
    
        &#125;
    &#125;
    There was one place where no type where defined, I typed it as an int. Line: 145, check that out, so I don't screw something else up for you.

    regards.

  10. #10
    Just Joined!
    Join Date
    Jun 2004
    Posts
    16
    Thanks so much guys. Everything is compiling now without errors. I prefer having forgot those simple brackets rather than discovering that I really don't understand a notion...

    Quote Originally Posted by kyku
    [...]it's mainly because of the crappy coding style you use (sorry
    Ok, sorry . What do you suggest me to adopt a better coding style ?

    I have written the entire program with VI. What should I use as editor ?

    Your 30sec (probably more) helped me a lot as the topic says on the forum.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •