Thread: Problem with BGI graphics: Linker Error

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    9

    Problem with BGI graphics: Linker Error

    Hey. I had just started work on a certain BGI graphics mini project, when I discovered a totally new problem. Whenever I try to compile the program below, it gets compiled with no errors and no warnings. However, when I try to run the program, I get linker errors related to each of the functions defined in graphics.h

    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<graphics.h>
    #include<math.h>
    #define XINTERVAL 100
    /////////////////////////////////////////////////////////////////////
    void showgraph()
    {
    	int gd=DETECT,gm,currentx,ctr,ctr2;
    	clrscr();
    	initgraph(&gd,&gm,"c:\\tc\\bgi");
    
    	cleardevice();
    	moveto(1,1);
    	currentx=1;
    	setcolor(BLUE);
    
    	ctr2=0;
    	ctr=1;
    	while(getx()<=getmaxx())
    	{
    		line(currentx,1,currentx,getmaxy());
    		ctr++;
    		currentx=XINTERVAL*ctr2+log10(ctr)*XINTERVAL;
    		if(ctr==10)
    		{
    			ctr=1;
    			ctr2++;
    		}
    	}
    
    	getch();
    
    	closegraph();
    	restorecrtmode();
    }
    /////////////////////////////////////////////////////////////////////
    int main()
    {
    	clrscr();
    	showgraph();
    	getch();
    	return(0);
    }
    The program seems simple enough, so I am unable to understand why I should get any errors at all. The problem is that I am writing a BGI graphics program after a very long time, and did not anticipate any problem. Moreover, programs that I had earlier written and compiled correctly, now give me the same errors when I try to run them from within the compiler. What could be the problem? Please help out.

    Compiler: Turbo C++ v3.0
    OS: Microsoft Windows XP, Home Edition, Version 2002, Service Pack 2
    Computer: AMD Athlon XP 2000+, 1.66 GHz, 224 MB RAM
    Last edited by darklord1984; 07-28-2005 at 03:07 PM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Perhaps you have to link the library for the BGI to your program? Maybe under "Compiler options"?

    programs that I had earlier written and compiled correctly, now give me the same errors when I try to run them from within the compiler.
    Run them from the DOS prompt.

    What is the exact linker error? There appears to be a reference to "c:\\tc\\bgi" . . . does that exist?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Code:
    Linker Error: Undefined symbol _restorecrtmode in module NONAME00.CPP
    Linker Error: Undefined symbol _closegraph in module NONAME00.CPP
    Linker Error: Undefined symbol _getmaxx in module NONAME00.CPP
    Linker Error: Undefined symbol _getx 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 _setcolor in module NONAME00.CPP
    Linker Error: Undefined symbol _moveto in module NONAME00.CPP
    Linker Error: Undefined symbol _cleardevice in module NONAME00.CPP
    Linker Error: Undefined symbol _initgraph in module NONAME00.CPP
    The above list comprises the errors I get, only at runtime, not at compile-time. Could it have something to do with my operating system, as that is the only thing that has changed since my last BGI graphics program. Earlier I had Microsoft Windows 98 SE.

    The path "c:\\tc\\bgi" is correct.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > Compiler: Turbo C++ v3.0
    A steam engine

    > Computer: AMD Athlon XP 2000+, 1.66 GHz, 224 MB RAM
    A Ferrari

    Try getting some software development kit which is more in tune with the OS and hardware which you're using.
    Say Dev-C++ compiler with the libSDL graphics package.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Is this problem occuring because of my operating system? Does the program run correctly on any other PCs with Windows XP?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well there's always the problem of compatibility.
    And you'll never get those nice high resolution and high colour scenes
    And unless you're maintaining some code, the BGI interface isn't worth knowing, since you'll need to learn another one just to get anything useful done.

    The immediate problem is you didn't specify a library (you only specified a header file, which is enough for the compiler), but you also need to tell the linker where the actual code is that will do the work.

    Idealised command line - read the compiler manual for your exact syntax.
    bcc NONAME00.CPP graphics.lib
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Hey, I got the solution. I guess I had to enter the path in the linker options. Thanks Salem.

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    1

    With Turboc

    Hi! i had the same error with Turbo c++ 3.0

    Just browse to Options>Linker>Libraries>
    and select the option "Graphics Libraries"

    It starts working then....

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Hey. I had just started work on a certain BGI graphics mini project, when I discovered a totally new problem.
    BGI in itself is a huge problem. Opt not to use it and favor something built at least within the last decade.

    With the release of MSVC Express Edition, the tons of information available about Direct3D and OpenGL, and the many libraries available for both there is 100&#37; absolutely no reason to ever trouble yourself with BGI.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    And the thread was 2 years old before anagile decided to demonstrate that they hadn't read the rules.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM