User forums > General (but related to Code::Blocks)

Problems with graphics.h and winbgim.h; redefinition of 'int right'

<< < (2/4) > >>

codeur:
WinBGIm is one of the easiest 2D graphics library in existence. Several hundreds of students have used it without a problem under Codeblocks-EP.

If you installed Codeblocks-EP, you'll find another such library there, called GRX. It is not as simple as WinBGIm.
Your question relates to coding or understanding how software libraries work. This is not related to Code::Blocks, so we cannot help you further on this forum.

WhoAmI:
Thank you, the problem was solved. And I should apologize because it was slightly stupid my mistake. I have installed EP version of Code Blocks but I was always creating Console application, not WinBGIm project.
 But what's interesting, that I have built three projects with the identical code. The first is Console application C++; second is WinBGIm C++ and third is WinBGIm C project. First didn't work but two others compiled and worked properly. But anytime I looked into compiler flags (Project -> Build Options; am I right in the location?) settings were same for all three projects.

 And here is the code if you want to see

--- Code: ---#include <conio.h>
#include <graphics.h>

int GrafInic () {
  int gdriver,gmode;
   gdriver=DETECT;
  initgraph (&gdriver, &gmode, "");
  return graphresult()==grOk;
}

int main () {
  if (!GrafInic ()) return 1;

  line (0,0,100,100);
   line (100,100,0,100);
   line (0,100,0,0);
   getch ();

   closegraph ();
   return 0;
}

--- End code ---

codeur:
Follow-up of this topic now on Dev Shed: http://forums.devshed.com/beginner-programming-16/problems-with-graphics-h-and-winbgim-h-redefinition-of-int-842275.html

harrykar:
I reply in that OLD thread only because actually i am in the same situation and i found a banal typo error in graphics.h;
downloaded from mantainer's website; i notice too many posts throughout the web refer to that problem;
I suppose that library is quite old and i am wondering how all that time the maintainer prof Main was not aware about
i.e. how no one in the world complained to him --instead complain on the forums-- about that annoyance;   
Hopefully now on newcomers (mostly students i guess) will compile and run their winbgim app without that particular
headache

Enjoy


Let's recap
As @WhoAmI reported the following error is presented to me too but the fact is that C:B(Release 13.12  rev 9501 (2013/12/25 19:25:45)   gcc 4.7.1 Windows/unicode - 32 bit)/mingw(4.8.1) system is right 

--- Code: ---c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|302|error: redefinition of 'int right'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\graphics.h|302|error: 'int right' previously declared here|
||=== Build finished: 2 errors, 0 warnings ===|

--- End code ---

i did a try also with Geany/mingw system and the result was the same(always with same mingw)

--- Code: ---g++ -m32  -Wall  -std=c++11  -pedantic -g   "first-sample.c" -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32  -o "first-sample.exe" (in directory: C:\Documents and Settings\Owner\Επιφάνεια εργασίας\BOB\cources\NPTEL\books\Progr\lang\Cbooks\C50books\test)
In file included from c:\mingw\include\graphics.h:29:0,
                 from first-sample.c:1:
c:\mingw\include\graphics.h:302:40: error: redefinition of 'int right'
     int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
                                        ^
In file included from first-sample.c:1:0:
c:\mingw\include\graphics.h:302:27: error: 'int right' previously declared here
     int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
                           ^
Compilation failed.


--- End code ---
 

so my curiosity rise high and i saw that in line 302 graphics.h had a typo error.

--- Code: ---  ...  int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX, ...
--- End code ---

to be surest i downloaded the C:B-EP and compare my file with the graphics.h there and definitely my graphics.h ( i had downloaded it  from Mainland's Uni page** http://www.cs.colorado.edu/~main/cs1300-old/cs1300/doc/bgi/bgi.html precisely from http://www.cs.colorado.edu/~main/bgi/dev-c++/ --because was the first result in google--) had that typo error.


So all we in the world (except maybe the lucky users of CodeBlocks-EP) had an erratic graphics.h file

I notify (i hope main@colorado.edu is  a valid/active email address) Michael Main trough an email about that hopefully he will correct it. Meanwhile i hope this post be proficient for who encounter the above mentioned errors 

PS:
After have corrected the graphics.h  (int right=0 --> int top=0 ) actually the sample program first-sample.cxx compile flawlessly  but crash in runtime :(. Ok that's another problem. 

Instead C:B_EP work as intended;

<edit>
About first-sample.c 's crashing i have followed prof. Main's instructions (download graphics.h , libbgim.a and put them in \include and \lib dirs respectively but  Main refers to his CSCI 1300 Software Package instead i put them in mingw's \include and \lib dirs  i guess the problem is there; when i have time to see what is going on i post here 
<edit\>

<final_edit 18/07/14>
was not a file's placement in the right directories issue but a libbgim.a "oldness" problem (thanks for the hint codeur ;) ) i.e. libbgim.a was too old to live and behave as intended so i downloaded the library's source from http://winbgim.codecutter.net/ and recompile it with the actual version of mingw (4.8.1) and substitute the freshly
compiled libbgim.a in place of the ancestral  libbgim.a(downloaded from the maintainers webpage ) and as if by magic all was tele-transported in our days and worked flawlessly as it should

Prof Micahel Main reply me (15/7/14) a thanking  for my advise but up to few minutes ago all his pages related to winbgim library remain as were. Dunno his timing constraints so meanwhile right now I put here as attachment the 2 necessary and sufficient files for use the library i.e. graphics.h and the newly compiled libbgim.a; a bit later i put them in my account in github too.
Unfortunately here is not permitted upload .h and .a (i am wondered why?) files so after you download the files do not forget to delete the fake *.patch extension in each of them 
<final_edit\>



**
Many Computer Science faculty have recommended the use of graphics to help
motivate the study of introductory programming and as a vehicle to help students
understand how to use libraries and to call functions.
To reduce the overhead required to introduce graphics, we  decided to use
WinBGIm (Windows BGI with the addition of mouse control), which is a package based
on the Turbo Pascal BGI (Borland Graphics Interface) library.
WinBGIm was created to run on top of the Win32 library by Michael Main and his
students at the Computer Science Department, University of Colorado Boulder.
Several development platforms appropriate for CS 1 courses have incorporated
WinBGIm. Quincy (developed by Al Stevens) is an open-source student oriented
C++ IDE that includes WinBGIm as well as more advanced libraries.
A command-line platform based on the open-source GNU g++ compiler and  the
emacs program editor is distributed by the University of Colorado. WinBGIm is
also available for (n.d.r. nowadays deprecated and buggy) Bloodshed Software’s Dev-C++ ,
Microsoft’s Visual Studio C++ (n.d.r and obviously for Codeblocs - Edu Portable that includes
as well other more advanced libraries) .

excerpt from Hanly-Koffman's Problem Solving and Program Design in C



Cheers,
Harry


[attachment deleted by admin]

codeur:
Thanks Harry, this explains why this error keeps on reappearing, while many people had no errors.
The typo is in the parameters declaration of function printimage.
This typo obviously slipped at some stage into the original distribution at colorado.edu. It is not found in the distribution  at http://winbgim.codecutter.net/ which was itself downloaded from colorado.edu before the typo got in.
Codeblocks-EP uses the codecutter release which works OK.

Your fix to the code is incorrect, which can explain why your program crashes afterwards. The correct code is:


--- Code: ---void printimage(
    const char* title=NULL,
    double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
    int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
    bool active=true, HWND hwnd=NULL
    );
--- End code ---

We are much obliged to you for resolving this old mystery.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version