Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

c - Unable to run graphics.h program in windows shell

I'm trying to run this program on through gcc on Windows shell. GCC version that I'm using:

gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The code:

#include<stdio.h>
#include<graphics.h>
int main(){
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "");
    line(150,150,450,150);
    getch();
    closegraph();
}

At first, it was giving me this error:

fatal error: graphics.h: No such file or directory
     #include<graphics.h>

Then I added the graphics.h file to my gcc directory. But now it is showing this error:

Gph.C: In function 'int main()':
Gph.C:5:24: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  initgraph(&gd, &gm, "");
                        ^
C:UserssimpleAppDataLocalTempcchdXkih.o:Gph.C:(.text+0x2e): undefined reference to `initgraph'
C:UserssimpleAppDataLocalTempcchdXkih.o:Gph.C:(.text+0x52): undefined reference to `line'
C:UserssimpleAppDataLocalTempcchdXkih.o:Gph.C:(.text+0x63): undefined reference to `closegraph'
collect2.exe: error: ld returned 1 exit status

Can someone suggest an alternative way to run my program? I've already tried running it on Visual Studio and Online Compilers.

question from:https://stackoverflow.com/questions/65909961/unable-to-run-graphics-h-program-in-windows-shell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use CodeBlocks IDE for it. Link.

Or you can also use TurboC++ but you will have to make a minor change to your code:

#include<stdio.h>
#include<graphics.h>
int main(){
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\TURBOC3\BGI");
    line(150,150,450,150);
    getch();
    closegraph();
}

An advantage of using TurboC++ is that you will not have to download any extra files to run your graphics.h programs unlike other IDE like CodeBlocks or DevC++.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...