Author Topic: Problems with graphics.h and winbgim.h; redefinition of 'int right'  (Read 45414 times)

Offline WhoAmI

  • Single posting newcomer
  • *
  • Posts: 4
Hello!

I am trying to do some simple graphic programs. But I can't build my project because I always get this error message:
Code: [Select]
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 ===|
.
The same error occurs in winbgim.h. I am not sure if I posted this topic to the right forum, but anyway I don't know if is it really library problem or incorrect settings of my IDE.

I have downloaded files mentioned in subject from here: http://www.mediafire.com/?hokmzgomtje and did everything according to these instructions http://gagsays.wordpress.com/2010/04/27/bgi-graphics-for-windows-on-request/. I also tried download from here http://codecutter.org/tools/winbgim/, but the situation repeated.

Did anybody have the same problem? And does anybody haveany idea how to fix it?

I am using Code::Blocks 10.05 IDE, Windows XP Service pack 2.
« Last Edit: August 18, 2011, 10:07:03 pm by WhoAmI »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6548
    • My Best Post
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #1 on: August 19, 2011, 12:11:33 am »
Turn on Full Compiler Logging and post in a forum that supports your compiler or library.
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

This site supports neither.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6548
    • My Best Post
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #2 on: August 19, 2011, 04:46:45 am »
Note: The Codeblocks-EP in this thread has the winbgim in it.
You might wish to try it. I have not tried it.

http://forums.codeblocks.org/index.php/topic,15135.0.html


Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #3 on: August 19, 2011, 08:28:30 am »
WhoAmI,

The error message is caused by multiple compilations of graphics.h because you are using a poorly built version of WinBGIm without the standard protection in the headers.

You can protect winbgim.h and graphics.h by surrounding all the code with:
#ifndef WINBGI_H
#define WINBGI_H

.... The existing header code

#endif

OR (better suggestion):
Either
1- install CodeBlocks-EP and use the inbuilt WinBGIm (create a winbgim project in Codeblocks-EP).
or
2- download the correct library from http://winbgim.codecutter.org and install the correct library instead of yours.

- 1 is safer, WinBGIm works very well in Codeblocks-EP. The WinBGIm project will link the correct libraries, you get WinBGIm help in the help menus, etc...
- 2 will probably also work unless you use a very different version of MinGW.

Offline WhoAmI

  • Single posting newcomer
  • *
  • Posts: 4
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #4 on: August 20, 2011, 12:34:42 am »
Thank you for help. Although I have tried all your advices, none of them did work. I am really confused of it. Maybe I should look for some other libraries. Do you have any tip for simple 2D graphic?

Anyway, I thank you very much for your effort to help.

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #5 on: August 20, 2011, 01:46:04 am »
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.

Offline WhoAmI

  • Single posting newcomer
  • *
  • Posts: 4
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #6 on: August 20, 2011, 09:14:43 pm »
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: [Select]
#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;
}

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable

Offline harrykar

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #8 on: July 15, 2014, 08:49:48 pm »
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: [Select]
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 ===|

i did a try also with Geany/mingw system and the result was the same(always with same mingw)
Code: [Select]
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.

 

so my curiosity rise high and i saw that in line 302 graphics.h had a typo error.
Code: [Select]
  ...  int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX, ...
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]
« Last Edit: August 14, 2014, 01:10:03 pm by harrykar »
--"Arguing with an engineer is like wrestling with a pig in the mud; after a while you  realize you are muddy and the pig is enjoying it." <br />-- Don't Learn to HACK - Hack to LEARN <br />-- cyberwarfare is now an active part of information warfare

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #9 on: July 16, 2014, 01:23:51 am »
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: [Select]
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
    );

We are much obliged to you for resolving this old mystery.
« Last Edit: July 16, 2014, 01:57:33 am by codeur »

Offline harrykar

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #10 on: July 18, 2014, 12:36:44 pm »
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.

exactly so codeur  ;)


Quote
This typo obviously slipped at some stage into the original distribution at colorado.edu.

I'm pretty new to winbgim library; i am aware of that library-and impact on that problem- definitely casualy; only  because is used in a CS introductory book Problem Solving and Program Design in C i have to do a review for an educational institution; so far i ignore about library's existence and yes in the end 80's early 90's i bought (hardly with my few student's money) Borland's Pascal ,C compilers and assembler pack version 3.something but not remember had use that library. Back in that era graphics stuff were pretty new and strange/experimental for all us.

 
Quote
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.

So (if you remember well had not patch it in past) that typo was entered after you had download (either binary or source) your own copy for  Codeblocks-EP and the typo was introduced later. Only in that manner make sense IMHO. Right now if you download the library (either the binary or the source) from winbgim.codecutter.net or Main's .../bgi site you can ensure that graphics.h as winbgim.h too continue to be erratic as were


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

Code: [Select]
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
    );

No my fix was exactly as what you have written above. The crash was due (as you had hint me) to libbgi.a 's  "oldness". Last but not least the new libbgi.a is smallest (-5KB) than the ancestral one mean the nowadays GCC is more effective than his great grandfather :)
Moreover is interesting note that make was not complained about graphics.h but about winbgim.h (on the same line:collumn --as gcc previously complained on graphics.h); see attachment ; graphics.h before build is erratic after winbgim.h 's correction and build  graphics.h becomes correct;


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

You make me feel like Indiana Jones lol :D Thank you very much for your compliment you're welcome  ;).
If permitted  i will publicly
Thank especially you for your hint that help resolve the particular arcane,
Thank the people here that did and do hard work and permit us to use a very good IDE,
and for induction Thank all that people that permit open source, open edu, open mind  and openess in general because permit all us live better


PS:
1. @codeur: Thank you for your email i reply later about C:B-EP
2. For the mods admins here: maybe is better insert a [resolved] in the object of the 1st post  


My Best Regards
Harry G. K.


[attachment deleted by admin]
« Last Edit: July 20, 2014, 01:25:36 pm by harrykar »
--"Arguing with an engineer is like wrestling with a pig in the mud; after a while you  realize you are muddy and the pig is enjoying it." <br />-- Don't Learn to HACK - Hack to LEARN <br />-- cyberwarfare is now an active part of information warfare

Offline harrykar

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #11 on: July 18, 2014, 05:09:37 pm »
I saw around in the wild some people use winbgim.h instead of graphics.h ; seems that graphics.h were used with Borland's compiler/dev environment instead with other compilers/ dev environments people use winbgim.h. Personally i can say that graphics.h goes well with mingw/C:B or whatever IDE has mingw as backend.

Cause the limit of 2 files per post in the earlier post i preferred upload graphics.h so for the sake of completeness (for who has just some code using winbgim.h instead of graphics.h) here i upload the corrected winbgim.h

Cheers,
Harry       
« Last Edit: August 14, 2014, 01:03:58 pm by harrykar »
--"Arguing with an engineer is like wrestling with a pig in the mud; after a while you  realize you are muddy and the pig is enjoying it." <br />-- Don't Learn to HACK - Hack to LEARN <br />-- cyberwarfare is now an active part of information warfare

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6548
    • My Best Post
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #12 on: July 18, 2014, 08:55:57 pm »
FYI: All files linked to a posts will be deleted at some future time.
This website admins deletes old attached files when the server space gets too low.

It is better to find a file hosting site and post links to the file on that site.

About winbgim.h.patch attachment.
Please learn to make file patches!!!
Wasting the bandwidth to download files that are NOT zipped is wasteful!!

Tim S.
« Last Edit: July 18, 2014, 08:59:45 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline harrykar

  • Multiple posting newcomer
  • *
  • Posts: 20
Re: Problems with graphics.h and winbgim.h; redefinition of 'int right'
« Reply #13 on: July 18, 2014, 09:52:57 pm »
FYI: All files linked to a posts will be deleted at some future time.

This website admins deletes old attached files when the server space gets too low.

Good to know thanks Tim


Quote
It is better to find a file hosting site and post links to the file on that site.

Is just what i wrote above in a former post; upload here is only temporary; time to put files on github  :) 

Quote
About winbgim.h.patch attachment.
Please learn to make file patches!!!

As i wrote above they aren't real patch files but a workaround to "elude" the dump upload system here


Quote
Wasting the bandwidth to download files that are NOT zipped is wasteful!!

Tim S.

Don't got it, you're kidding me right ?  :)
13.5KB wast bandwidth? and should be zipped?  ???
LOL  didn't did it not even when we were in paleolithic modems 35Kbps era;  anyway next time i try to remember it


Cheers,
Harry G. K.

« Last Edit: August 14, 2014, 01:05:25 pm by harrykar »
--"Arguing with an engineer is like wrestling with a pig in the mud; after a while you  realize you are muddy and the pig is enjoying it." <br />-- Don't Learn to HACK - Hack to LEARN <br />-- cyberwarfare is now an active part of information warfare