Search code examples
c++codeblocksdev-c++bgi

Can't get pass C++ warning: (& crash after) deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]


I tried everything, and I can't even start this simple graph code. I have installed the graphics.h, winbgim.h and libbgi.a in all the right folders. (include and lib). Linkers, too -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

I'm using CodeBlocks 16.01. I have also tried it in Dev-C++ with no luck.

First I got error:

C:\Program Files (x86)\CodeBlocks\MinGW\include\graphics.h|302|error: redefinition of 'int right'

But I solved that by changing the graphics.h file, int right needs to be replaced with int top.

Also there is 1 warning -

C:\Users\Davor\Desktop\New Project\drugi\main.cpp||In function 'int main()':| C:\Users\Davor\Desktop\New Project\drugi\main.cpp|15|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]| ||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

After that, when I press 'Build and run' i get

" *.exe has stopped working. " In the background I first get -

Process returned 255 (0xFF) execution time : 91.666 s Press any key to continue.

But every other time I get -

Process returned -1073741819 (0xC0000005) execution time : 26.494 s Press any key to continue.

#include <iostream>
#include <cstdlib>
#include <graphics.h>


using namespace std;



int main() {

    int gdriver = 9;
    int gmode = 2;
    int x;
    initgraph(&gdriver, &gmode, "");
    setbkcolor (WHITE);
    setcolor (BLACK);
    cleardevice();
    for (x = 260; x < 364; x = x + 5)
    {
        circle(x,240,60);
    }
    getch();
    closegraph();

    return 0;
}

Solution

  • I have found the solution.

    The problem was in the next library:

    libbgi.a

    I have tried sever different ones, but at the end I found the right one. As soon as I replaced it with the old one - the graphic window opened and worked just fine, without crashes.

    The warning:

    deprecated conversion from string constant to 'char*' [-Wwrite-strings]|

    is still there, but the code works perfectly.

    Thanks for help anyway.

    Cheers.