How to use graphcis.h

This is a discussion on How to use graphcis.h within the C Programming forums, part of the General Programming Boards category; Hi, I am trying to use graphics.h library on a program, I copied the example of a program that comes ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    66

    How to use graphcis.h

    Hi, I am trying to use graphics.h library on a program, I copied the example of a program that comes in help, however, it does compile but at the time I try to run it, it shows a lot of linker Errors, I really don't know what do they mean and why are there appearing, so, if anyone knows something, I would really appreciate help on this, Thanx

    The program I am trying to use is the example to draw a line, here it is:

    Code:
    #include <graphics.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    
    int main(void)
    {
       /* request auto detection */
       int gdriver = DETECT, gmode, errorcode;
       int xmax, ymax;
    
       /* initialize graphics and local variables */
       initgraph(&gdriver, &gmode, "");
    
       /* read result of initialization */
       errorcode = graphresult();
       /* an error occurred */
       if (errorcode != grOk)
       {
          printf("Graphics error: %s\n", grapherrormsg(errorcode));
          printf("Press any key to halt:");
          getch();
          exit(1);
       }
    
       setcolor(getmaxcolor());
       xmax = getmaxx();
       ymax = getmaxy();
    
       /* draw a diagonal line */
       line(0, 0, xmax, ymax);
    
       /* clean up */
       getch();
       closegraph();
       return 0;
    }

    The linker errors it shows are:

    Linking NONAME00.EXE:
    Linker Error: Undefined symbol _closegraph in module NONAME00.CPP
    Linker Error: Undefined symbol _line in module NONAME00.CPP
    Linker Error: Undefined symbol _getmaxy in module NONAME00.CPP
    Linker Error: Undefined symbol _getmaxx in module NONAME00.CPP
    Linker Error: Undefined symbol _setcolor in module NONAME00.CPP
    Linker Error: Undefined symbol _getmaxcolor in module NONAME00.CPP
    Linker Error: Undefined symbol _grapherrormsg in module NONAME00.CPP
    Linker Error: Undefined symbol _graphresult in module NONAME00.CPP
    Linker Error: Undefined symbol _initgraph in module NONAME00.CPP


    Thanx again

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    You'll have to link to the graphics lib. . . I think you are using an old compiler though. . . which one are you using?

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    Yep, I am using a quite old compiler, but using a newer is not allowed, because it is going to be run on this one.
    I am using Turbo C++ Version 3.0

    Ok, on options->linker->libraries I activated Graphic libraries, I can run the program now, however it throws at me another error, now while it is running:
    Graphics error: Device Driver File not found (EGAVGA.BGI)

    Could anyone explait to me what does this Mean? Do I have to download or configure anything extra?
    And if th's the case, could someone tell me where or how can I do it?

    Thanx again
    Last edited by louis_mine; 11-13-2006 at 05:30 PM.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Yeah, a newer compiler
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    Quote Originally Posted by manutd
    Yeah, a newer compiler
    Oh, so fun, specially because I said I couldn't use a newer one.
    Anyway, I've already solved this problem, I was missing the BGI library and now it works just fine

    Thanks for the help

  6. #6
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    hehe...whoops What class/application are you taking/programming that requires you to use TC 3.0?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    66
    I am working on a Compiler, it is supposed to use the least resources it can and it must be done from nothing, so, we are not allowed to use newer versions of TC (I believe is a lot of Teacher's desire to make it harder)

  8. #8
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Nice, tough assignment, tough requirements, ugly compiler...I've had one of those teachers
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  9. #9
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    I have some code that I have to use TC 3.0 on. . . it is very buggy. Just FYI.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21