-1

I am trying to build a cpp program in codeblocks, that includes graphics.h file in it.

But I am getting a

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

  initgraph(&gd, &gm, "");

The warning is treated as errors: I have modified all the linker settings to include graphics.h in codeblocks.

initgraph(&gd, &gm, "");

Codeblocks shows:

=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===

genpfault
  • 51,148
  • 11
  • 85
  • 139
Rubin Shah
  • 73
  • 1
  • 8
  • 1
    It is not a linker error. Note that the function `void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);` does not use the `const` qualifier for `pathtodriver` (even though this is not an output parameter), but you pass a read-only argument. – Weather Vane Aug 06 '19 at 07:40
  • @AnttiHaapala Mate, cpp compiler compiles c code. And initgraph() is a c function in graphics.h, so my question and tags are all appropriate. – Rubin Shah Aug 06 '19 at 07:43
  • 3
    "Warnings are being treated as errors". This is **exactly** what you want. Don't touch this setting, – n. m. could be an AI Aug 06 '19 at 08:03
  • Did you specify to treat warnings as errors? To fix this warning try `static char emptystring[] = ""; /* ... */ initgraph(&gd, &gm, emptystring);`. – Bodo Aug 06 '19 at 08:03
  • 1
    There is no such thing as "cpp program"̇. There is a language called C, and a language called C++. These are two different languages. – n. m. could be an AI Aug 06 '19 at 08:06
  • Adding C++ tag since the issue is about cross compiling old C libs in C++. – Lundin Aug 06 '19 at 09:19
  • 1
    A C++ compiler compiles C++ code. A C compiler compiles C code. A C compiler might compile an excerpt of C++ code, as it could look like it makes sense as C. A C++ compiler might compile an excerpt of C code as it could look like it makes sense as C++. – Antti Haapala -- Слава Україні Aug 06 '19 at 09:23

1 Answers1

1

The problem is that C++ nowadays const qualify all string literals, unlike C and pre-standard C++. TC++ and Borland BGI is from the pre-standard days, so it won't compile cleanly with standard C++.

Best work-around:

char empty[] = "";
initgraph(&gd, &gm, empty);

Quick & dirty work-around:

initgraph(&gd, &gm, (char*)"");

You might also want to ask yourself why you are using 30 years old outdated libs written for MS DOS.

Lundin
  • 195,001
  • 40
  • 254
  • 396