#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0

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


    I am trying to do some simple graphic programs in Code::Blocks IDE. But I can't build my project because I always get this error message:
    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 ===|
    The same error occurs in winbgim.h. 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...ws-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.
    EDIT: And I am using MinGW compiler. This error is found always in these header files, not in main.
    Last edited by Kto_Som; August 18th, 2011 at 08:14 PM. Reason: completing information
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0
    Originally Posted by Kto_Som
    I am trying to do some simple graphic programs in Code::Blocks IDE. But I can't build my project because I always get this error message:
    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 ===|
    The same error occurs in winbgim.h. 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...ws-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.

    EDIT: And I am using MinGW compiler. This error is found always in these header files, not in main.
    Hi Kto_Som, We discussed this earlier on the code::blocks forum. This forum is more suited to your question, also you give more information now, so I can help better.

    The command line shown on the web page where you got the instructions is incorrect, and the instructions themselves are very incomplete.

    The problem is that you write a C program (with .c extension) whereas WinBGIm (including graphics.h) is written in C++.

    WinBGIm can be used without any trouble from a C program, but then you must do one of 2 things: either you give your file a .cpp extension (and then codeblocks will be able to compile your C++ header file, or you add the -x c++ compiler flag for your compilation. You also need other libraries than those given on that web page, and other compiler flags are sometimes needed as well.

    If you still have issues, the easiest as we said earlier is to install Codeblocks-EP from http://codeblocks.codecutter.org and to compile your file as part of a WinBGIm project. The project will then automatically set up the correct compilation flags and link libraries.

    The compiler and linker lines for a myprog.c program under Codeblocks-EP will look like:
    Compiler:
    gcc.exe -Wall -Wno-write-strings -x c++ -std=c++98 -pedantic -O2 -II:\apps\CodeBlocks-EP\sdk\winbgim\include -c I:\program\WinBGIm\all-tests\myprog.c -o obj\Release\myprog.o
    Linker:
    g++.exe -LI:\apps\CodeBlocks-EP\sdk\winbgim\lib -o bin\Release\myprog.exe obj\Release\myprog.o -s -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -mwindows
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0
    Thank you. And I should apologize because it was very 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.
    Anyway, I thank you, because it works now.

    And here is that 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;
      }
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    2
    Rep Power
    0
    Originally Posted by Kto_Som
    ...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.
    Anyway, I thank you, because it works now.
    ...
    You can find the compiler flags for a WinBGIm project in Codeblocks-EP by going to [Project]->[Build options..], tab [Compiler settings] and inner tab "Other options".
    The [Linker settings] tab lists the necessary libraries.

    The initwindow() function of WinBGIm advantageously replaces initgraph()

    The WinBGIm help in Codeblocks-EP ([Help]->[Programmer's Guide (HTML)]->[WinBGIm Library]) shows all the WinBGIm functions available.

    Use the following program as an example:
    Code:
    /**
     * File 32colors.c
     * Display some of the colours available to WinBGIm programs
     * Demonstrates how extra colours can be defined beyond the standard 16 ega colours given
     * in graphics.h
     *
     * @author jlk
     * @version 1.01 11-02-2011
     */
    #include "graphics.h" // Provides BGI graphics
    
    // Geometric constants
    const int START_X_POS = 16;
    const int X_SPACING = 190;
    const int START_Y_POS = 18;
    const int Y_SPACING = 36;
    const int XRADIUS = 35;
    const int YRADIUS = 16;
    const int NAMEWIDTH = 130;
    const int BK_COLOUR = WHITE;
    
    // Define 16 extra colours to give more choice
    const int CRIMSON           = COLOR(220, 20, 60);
    const int CHOCOLATE         = COLOR(210, 105, 30);
    const int GOLDENROD         = COLOR(218, 165, 32);
    const int DARKORANGE        = COLOR(255, 140, 0);
    const int REDRED            = COLOR(255, 0, 0);
    const int DARKSLATEGRAY     = COLOR(47, 79, 79);
    const int DEEPPINK          = COLOR(255, 20, 147);
    const int TURQUOISE         = COLOR(64, 224, 208);
    const int DARKVIOLET        = COLOR(148, 0, 211);
    const int BEIGE             = COLOR(245, 245, 220);
    const int MEDIUMSEAGREEN    = COLOR(60, 179, 113);
    const int LIMEGREEN         = COLOR(50, 205, 50);
    const int DARKGREEN         = COLOR(0, 100, 0);
    const int MEDIUMBLUE        = COLOR(0, 0, 205);
    const int BLUEBLUE          = COLOR(0, 0, 255);
    const int DODGERBLUE        = COLOR(30, 144, 255);
    
    // Define a color and name pair
    typedef struct
    {
        const char *name;
        int rgb;
    }  Colour;
    
    // Prototypes
    
    /**
     * Displays a colour in an ellipse with its name
     * @param clr - the colour to display
     * @param xpos - the x location of the colour display
     * @param ypos - the y location of the colour display
     * @param nameBefore - When true the colour name is diplayed ahead of the colour
     */
    void display(Colour clr, int xpos, int ypos, bool nameBefore);
    
    /*
     * Checks the mouse for click or keyboard for keypress.
     * @return true if neither the mouse was clicked nor the keyboard pressed.
     */
    bool watchMouse(void);
    
    int main(void)
    {
        // list array of pairs of "Colour" structs (visually matched if possible,
        // standard colours in left column, extra colours in right column)
        Colour avail[] =
        {   {"BLACK",        BLACK},         {"DARKSLATEGRAY",  DARKSLATEGRAY},
            {"BLUE",         BLUE},          {"BLUEBLUE",       BLUEBLUE},
            {"CYAN",         CYAN},          {"MEDIUMBLUE",     MEDIUMBLUE},
            {"LIGHTCYAN",    LIGHTCYAN},     {"TURQUOISE",      TURQUOISE},
            {"LIGHTBLUE",    LIGHTBLUE},     {"DODGERBLUE",     DODGERBLUE},
            {"MAGENTA",      MAGENTA},       {"DARKVIOLET",     DARKVIOLET},
            {"LIGHTMAGENTA", LIGHTMAGENTA},  {"DEEPPINK",       DEEPPINK},
            {"BROWN",        BROWN},         {"CHOCOLATE",      CHOCOLATE},
            {"RED",          RED},           {"CRIMSON",        CRIMSON},
            {"LIGHTRED",     LIGHTRED},      {"REDRED",         REDRED},
            {"YELLOW",       YELLOW},        {"GOLDENROD",      GOLDENROD},
            {"WHITE",        WHITE},         {"DARKORANGE",     DARKORANGE},
            {"GREEN",        GREEN},         {"DARKGREEN",      DARKGREEN},
            {"LIGHTGREEN",   LIGHTGREEN},    {"LIMEGREEN",      LIMEGREEN},
            {"DARKGRAY",     DARKGRAY},      {"MEDIUMSEAGREEN", MEDIUMSEAGREEN},
            {"LIGHTGRAY",    LIGHTGRAY},     {"BEIGE",          BEIGE}
    
        };
        int numColours = 32;
    
        // Put the machine into graphics mode and set window coordinates:
        initwindow(410, 590, "16 standard <+> 16 extra WinBGIm colors", 140, 80);
    
    
        setactivepage(0);
        // set window to white while drawing on the background page
        setbkcolor(BK_COLOUR);
        cleardevice();
    
        // Swap foreground and background pages
        setactivepage(1);
        setvisualpage(0);
    
        // set new backbround colour white to match
        setbkcolor(BK_COLOUR);
        cleardevice();
    
    	//Set font for colour names
    	settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 0);
    	setusercharsize(1, 2, 1, 2);
    	settextjustify(LEFT_TEXT, CENTER_TEXT);
    
        // Display colours in two columns
        for( int count = 0; count < numColours; count++)
        {
            int ypos = START_Y_POS + count / 2 * Y_SPACING;
            if(count % 2) // second column of colours
                display(avail[count], START_X_POS + X_SPACING, ypos, false);
            else // first column
                display(avail[count], START_X_POS, ypos, true);
        }
    
        // Swap foreground and background pages
        setvisualpage(1);
    
    	/* Check for mouse or keypress */
    	while(watchMouse())
    		delay(100);
    
        // finish
        closegraph( );
    }
    
    /*
     * Checks the mouse for click or keyboard for keypress.
     */
    bool watchMouse( )
    {
        if(ismouseclick(WM_LBUTTONDOWN) || ismouseclick(WM_RBUTTONDOWN))
            return false;
    
    	return !kbhit();
    }
    
    /*
     * Displays a colour in an ellipse with its name
     */
    void display(Colour clr, int xpos, int ypos, bool nameBefore)
    {
        if(clr.rgb == BK_COLOUR || clr.rgb == BEIGE)
            setcolor(BLACK);
        else
            setcolor(clr.rgb);
        setfillstyle(SOLID_FILL, clr.rgb);
    
        if(nameBefore) // Then display the name before (1st column)
        {
            outtextxy(xpos, ypos + 4 + YRADIUS / 2, clr.name);
            fillellipse(xpos + NAMEWIDTH + XRADIUS / 2 , ypos + YRADIUS / 2,
                        XRADIUS, YRADIUS);
        }
        else // name after (second column)
        {
            fillellipse(xpos + XRADIUS / 2 , ypos + YRADIUS / 2,
                        XRADIUS, YRADIUS);
             outtextxy(xpos + 3 * XRADIUS / 2 + 10, ypos + 4 + YRADIUS / 2, clr.name);
        }
    }
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0
    Originally Posted by Kto_Som
    I am trying to do some simple graphic programs in Code::Blocks IDE. But I can't build my project because I always get this error message:
    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 ===|
    The same error occurs in winbgim.h. 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...ws-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.
    EDIT: And I am using MinGW compiler. This error is found always in these header files, not in main.
    I think in codeblocks linker setting is not correct so please follow these link http://codeincodeblock.blogspot.com/2011/09/how-to-setup-winbgim-library-in.html you will get correct setting for winBGI graphics
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Wink


    it's because the header file or the library file has the same identifier for a variable

    your problem can be solved by changing the identifier from "right"
    to anything else
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    help me ... codeblock


    i am just using codeblock EP. i comoile my code with graphics.h header file. it shown me 0 error o warning. but when i run the programme it happen a error. let me explain.. a rectangle box come and it shown "drawing operation was attempted when there was no current window" . what can i do now.please help

    just another question, when i create a new winbgim project there was no field to write the code it just blank. then i create empty file and link together. is this appropriate way to coding in winbgim? if not then what it is?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2014
    Posts
    4
    Rep Power
    0

    Lightbulb


    Originally Posted by msbm
    it's because the header file or the library file has the same identifier for a variable
    You are right i report i will'n repeat the same here take a look at Problems with graphics.h and winbgim.h; redefinition of 'int right'

    Ceers,
    Harry

IMN logo majestic logo threadwatch logo seochat tools logo