Thread: having some trouble with function libraries

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    11

    having some trouble with function libraries

    Hey everyone. For some strange reason my program won't read in from the libraries I'm including at the top:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    #define  BUFFER_SIZE  70
    #define  TRUE          1
    #define  FALSE         0
    
    int**  img;
    int    numRows;
    int    numCols;
    int    maxVal;
    FILE*  fo1;
    
    void addtopixels(int** imgtemp, int value);
    void  writeoutpic(char* fileName, int** imgtemp);
    int** readpic(char* fileName);
    void  readHeader(FILE* imgFin);
    int   isComment(char* line);
    void  readImgID(char* line);
    void  readImgSize(char* line);
    void  readMaxVal(char* line);
    int** setImage();
    void  readBinaryData(FILE* imgFin, int** imgtemp);
    void  choice1();
    void  choice2();
    void  choice3();
    void sobelfunc(int** pic, int** edges, int** tempx, int** tempy);
    void  subtractpic(int** img1, int** img2, int** img3);
    
    int** temppicx;
    int** temppicy;
    int** img;
    int** sobelout;
    int choice;
    
    int brightness;
    char fileName1, fileName2; 
    
    int main()
    {
            char fileName[BUFFER_SIZE];
            int i,j,rows,cols;
            char ci;
    
            printf("Successfully read image file '%s'\n", fileName);
            
            printf("Which action would you like to perform?\n");
            printf("1. Edit the brightness.\n");
            printf("2. Subtract 2 images.\n");
            printf("3. Sobel edge highlighter.\n");
            prinft("4. Exit\n");
            scanf("%d", &choice);
            
            while (choice != 4) {
                  if (choice == 1) {
                             option1();
                             }
                             
                  if (choice == 2) {
                             option2();
                             }
                             
                  if (choice == 3) {
                             option3();
    }     
    
    }
    return(EXIT_SUCCESS);
    
    void option1()
    {
       printf("Enter image filename: ");
                             scanf("%s", fileName);
    
                             img = readpic(fileName);
                             
                             printf("By how much would you like to change the brightness?\n");
                             scanf("%d", &brightness);
                             
                             
                             addtopixels(img,brightness);
            
                             writeoutpic("out1.pgm",img);
    
                             free(img);
                             img = NULL;
                             }
    The error I'm getting is the following:

    [Linker error] undefined reference to 'readpic'

    Then where it says readpic is has a bunch of lines where it says the same for things like 'addtopixels', 'setImage', etc.

    Does anybody know what might be going wrong?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to also compile the file that has all those functions in it, or link to the library that is already compiled. (Either give both .c files on the command line, or add -lwhatever as appropriate.)

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    11
    I'm not sure I understand .. =/

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Those functions, from addpixel down to subtractpic, aren't standard C functions. You have to tell the compiler where they are.

    So now the question is: do you know where they are? Did you write them? Do you have source for them? Or are they in some library? If so, what is its name?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    11
    Aren't the library declarations at the top supposed to take care of that?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    But those functions aren't part of the standard libraries. No amount of including standard headers is going to get you functions that aren't standard. Why do you even think these functions exist? Edit: Are you in COP3223 at UCF? If so, you need to use the entire assign4.c file, not just the first forty lines or so.
    Last edited by tabstop; 11-10-2008 at 10:28 PM.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    11
    Wow, that was scary. How'd you figure that out, hehe

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    11
    I am using the entire file. I basically made a copy of it and started editing it adding in the options and such.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you were using the whole file, there would be all those functions at the bottom of the file: addtopixels, writeoutpic, readpic, readHeader, isComment, readImgID, readImgSize, readMaxVal, setImage, readBinaryData. If you deleted them, go download assign4.c again and get them back.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Those declarations only say that those functions exist somewhere - that is why they are declarations.
    The actual code must exist somewhere else - where it is defined. So you need both of those for it to work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  4. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM