The solution for doing graphics programming in ubuntu is:
libgraph - library providing the TurboC graphics API ( graphics.h) in Linux using SDL.
For using this , you need to follow some simple steps as mentioned below:
First of all, you need to install the dependencies so that all the required compiler tools gets installed. For that you need to run the given command on the terminal:
sudo apt-get install build-essential
Next you need to install some packages. They are: libsdl-image1.2, libsdl-image1.2-dev, guile-1.8 and guile-1.8-dev. For that run the given command at the terminal:
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev
Now, download and install libgraph-1.0.2.tar.gz from the link :
Download this file in any folder and extract it in the home folder or on the desktop wherever you want.
Open the terminal and navigate to the folder where you have extracted libgraph-1.0.2 with the help of cd command. Install this using the commands given below:
./configure (Return)
sudo make (Return)
sudo make install (Return)
After this you can start your C graphics programming in linux. Now try writing a simple C graphics program by including the header file "graphics.h". You can do the programs as you in TURBO C.
For writing the programs you can use the "gedit" tool in ubuntu. For compiling the programs, navigate to the source program folder and use the following command:
gcc filename.c -lgraph
For executing the program, use the command ./a.out
The error “./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory” can be solved by
sudo cp /usr/local/lib/libgraph.* /usr/lib
If you still have some furthur issues related to this post, post it here.
some error occurring while installing .....so I am unable to use it.
ReplyDeletekindly guide me....
Pls mention the error details u r getting....
ReplyDeletebresen.o: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
ReplyDeleteAborted
I get this message and the graph closes. Please help!
email:whisperingwind.sanjay@gmail.com
In turbo c++, i use :
ReplyDeleteint gdriver=detect,gmode,errorcode;
initgraph(&gdriver,&gmode,"C:\\tcplus\\BGI");
so whats the equivalent code here??
libgraph is so much equivalent to Turbo C++. It had been introduced keeping in view the users comfortable with Turbo C++.
ReplyDeleteSimply use:
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
U don't need to specify any path in initgraph. Even in Turbo C++,u can avoid writing the path in initgraph() by copying the file EGAVGA.bgi from BGI folder and pasting it in Bin folder.
The message u gave here flashes on the terminal due to initialization of the graph while u r receiving inputs. Just initialize the graph after u have entered the inputs.
ReplyDeleteJust consider ur example.Perhaps u were drawing line by bresenham algorithm.....Take the inputs from the user (in this case the end points of the line) before initializing the graph(or calling initgraph()).
If still anything happens....make me know....
One more thing...use the kbhit() function and closegraph() at the end for closing the graph.
thanks a lot! I got it working...
ReplyDeletethanks buddy its wotking
ReplyDeletehi shekhar,after entering the values a flash screen pops up and closes immediately ,so how can i be able to see the out put????no error mesgs are being displayed.
ReplyDeleteone more thing,,when i used conio.h its showing me error ---->no such file or directory<----
plzz help me get out of this ,,,chetan
conio.h is not available under libgraph...so just don't use it....
ReplyDeleteuse kbhit() or getch() function to see the output screen and then use closegraph() to close the graph.
write the following at the end of the program before return:
while(!kbhit());
closegraph();
This will do...if still u r unable to see the output, let me know..
Here a sample program for u. Try it..
#include
#include
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(100,100,50);
while(!kbhit());
closegraph();
return 0;
}
first include is stdio.h and the 2nd one is graphics.h...
ReplyDeletethank u shekar its working fine. i didn't expect such a quick repl from u,really thank u man.
ReplyDeletewhy should we use gcc filename.c -lgraph for compiling
ReplyDeleteisn't cc filename.c enough???(of course i did not get output using that command)
just clarify me, thanks in advance
gcc filename.c -lgraph is used to link the program with libgraph which contains graphics.h .
ReplyDeletecc instead of gcc will do but u need to append -lgraph at the end.
If u want a short command u can use
grc filename
For viewing the manual entry on libgraph, use the command " man libgraph ".
i get the following errors while installing >>>>>Makefile:934: warning: overriding commands for target `libgraph.pc'
ReplyDeleteMakefile:409: warning: ignoring old commands for target `libgraph.pc'
make install-recursive
make[1]: Entering directory `/home/rudrakshya/libgraph-1.0.2'
Makefile:934: warning: overriding commands for target `libgraph.pc'
Makefile:409: warning: ignoring old commands for target `libgraph.pc'
Making install in doc
make[2]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc'
Making install in man
make[3]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc/man'
make[4]: Entering directory `/home/rudrakshya/libgraph-1.0.2/doc/man'
make[4]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/man/man1" || mkdir -p -- . "/usr/local/man/man1"
mkdir: cannot create directory `/usr/local/man': File exists
make[4]: *** [install-man1] Error 1
make[4]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc/man'
make[3]: *** [install-am] Error 2
make[3]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc/man'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/home/rudrakshya/libgraph-1.0.2/doc'
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/rudrakshya/libgraph-1.0.2'
make: *** [install] Error 2
-pls help
Make sure you have you have installed build-essential and run the configuration command again.
ReplyDeletehi shekhar..i followed the steps and its working...thanks a lot!!! it ws xtremely helpful!!!
ReplyDeleteSDl window is small sized. How to get 640*480 graphics mode
ReplyDeleteFor 640*480 graphics mode, use the program statement:
ReplyDeleteint gd=DETECT,gm;
initgraph(&gd,&gm,"");
For further details on the enumerations used for graphics driver, see the documentation of libgraph. You can use 0 to 10 instead of DEFAULT. 0 gives the default enumeration.
When I am trying to compile file I got these errors
ReplyDelete/tmp/ccJKVMEj.o: In function `main':
graph.c:(.text+0x11): undefined reference to `grprintf'
collect2: ld returned 1 exit status
@Jayendra... Please post your program here. There's no problem related to the installation.
ReplyDeletethanks for grate blog
ReplyDeletecan we change then name of a.out
like if program is for circle then we can call circle.out
somthing
@GURU ... For that, you need to compile the program using the command:
ReplyDeletegcc filename.c -lgraph -o filename
And run it using "./filename". Quotes are not included in the command.
Consdering your example, the command for compilation would be "gcc circle.c -lgraph -o circle" and it can be executed using "./circle".
One more thing, the executable file can be generated with a name different from the source file using the command:
gcc filename.c -lgraph -o newfilename
and the program can be executed using the command:
./newfilename
One point to be noted in this case is that the .obj filename will be the same as the source file name.
/usr/bin/ld: cannot find -lgrpah
ReplyDeletecollect2: ld returned 1 exit status
i am encountering this error while compiling
@aryan
ReplyDeleteIt's "-lgraph" not "-lgrpah"
I still get an error when running the program:
ReplyDelete.. / .. / src / xcb_io.c: 249: process_responses: assertion `(((long) (dpy-> last_request_read) - (long) (dpy-> request)) <= 0) 'failed.
I've kept the initialization after the input process and use getch () and closegraphic ();
but still error when running ..
i am using ubuntu 10.10
Good Job Shekhar !!!
ReplyDelete@Situkangsayur..
ReplyDeleteI have tried this on Ubuntu 10.10 and it works fine. Try compiling it again. If the error persists , mail me the program so that i can have a look at it.
used your sample code:
ReplyDelete#include
#include
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(100,100,50);
while(!getch());
closegraph();
return 0;
}
error:
/tmp/ccUpRxaW.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
thanks for the solution
Thanks a lot!! I was searching for it like hell.
ReplyDeleteThanks once again!!!
Glad I could help.
ReplyDeleteHow to fill the rectangle with a color?
ReplyDeleteand how to make delay's in gcc for graphics programs?
how to draw rectangles of different line-widths?
ReplyDeleteRefer the documentation provided for graphics programming on the internet or some nice books. You will find everything there.
ReplyDeleteAs for filling a polygon flood filling method(recursive or non-recursive one) will do or you can make use of the others methods. C provides a built-in function for filling polygons (refer the documentation).
For making delay in gcc for graphics programs, make use of the delay() function. You can use any integral parameter for the delay function. Don't forget to include the necessary header files.
If still you have some problems send me your email id, i will mail you the programs for the same.
gcc doesn't include the DOS.H file which is neccessary for the DELAY function. What to do now?
ReplyDeletethanks a million sir , it worked for me too
ReplyDeletethis is my code
ReplyDelete#include
void main()
{
int gd=DETECT ,gm;
initgraph(&gd ,&gm,"E:/TC/BGI");
circle(150,150,150);
getch();
closegraph();
return 0;
}
when i compile this i get errors ..pls help me..
Desktop$ gcc CIR.C -lgraph
CIR.C:2:18: error: conio.h: No such file or directory
CIR.C:3: error: ‘::main’ must return ‘int’
CIR.C: In function ‘int main()’:
CIR.C:6: warning: deprecated conversion from string constant to ‘char*’
pls help me
R u execute this code in ubunto?
DeleteIf yes then u should include stdlib.h instead of conio.h
and also return type of main() is int
@Nisha
ReplyDeleteCIRC.C:2:18:error: conio.h: No such file or directory :- conio.h is not available in gcc. So just include it in your source file.
CIR.C:3: error: ‘::main’ must return ‘int’ :- Instead of void main() , make use of int main() and make sure you put the statement "return 0" in the end.
initgraph(&gd ,&gm,"E:/TC/BGI"); :- Change the path in the statement. It should be null . Make use of initgraph(&gd,&gm,""). The path you have mentioned in the program is used in case of the Turbo C compiler.
Hope it helps.
This comment has been removed by the author.
ReplyDeletei get the following error.
ReplyDelete/tmp/cc0y4aXz.o:POLYGON.CPP:(.text+0x1ad): more undefined references to `line' follow
/tmp/cc0y4aXz.o: In function `main':
POLYGON.CPP:(.text+0x28a): undefined reference to `grgetch'
collect2: ld returned 1 exit status
@shyam.. Post your program here. Can tell only after I see the program.
ReplyDeletei keep getting this error in the terminal while the graphic window is open, and it ultimately aborts the program.
ReplyDeletea.out: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
i have cleared the input output buffer prior to initialising the graph using getchar(). i would really appreciate it if you could tell me how this can be solved.
@Soham - Initialize the graph after u have received the inputs.
ReplyDeletefantastic post buddy.... helped a lot... thank you so much..
ReplyDeletethanks buddy...
ReplyDeletebut how to include "dos.h".
its not available in the packages.
do u have any way ???
dos.h provides functions for interrupts and system-level implementations in C under windows. Equivalent implementations can be achieved with the header file "signal.h" and various other header files present in the "/usr/include/sys" directory. Just check for the headers you need.
ReplyDeleteDelay and sleep functions can be used by including the "graphics.h" header file.
gcc a.c -lgraph
ReplyDeletea.c:4:2: error: invalid preprocessing directive #
a.c:5:1: error: stray ‘\302’ in program
a.c:5:1: error: stray ‘\240’ in program
a.c:6:1: error: stray ‘\302’ in program
a.c:9:1: error: stray ‘\302’ in program
a.c:9:1: error: stray ‘\240’ in program
a.c: In function ‘DDA’:
a.c:11:2: error: stray ‘\302’ in program
a.c:11:2: error: stray ‘\240’ in program
a.c:14:2: error: stray ‘\302’ in program
a.c:14:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:29:1: error: stray ‘\302’ in program
a.c:29:1: error: stray ‘\240’ in program
a.c:29:1: error: stray ‘\302’ in program
a.c:29:1: error: stray ‘\240’ in program
a.c:29:1: error: stray ‘\302’ in program
a.c:29:1: error: stray ‘\240’ in program
a.c:29:1: error: stray ‘\302’ in program
a.c:29:1: error: stray ‘\240’ in program
a.c: In function ‘midpoint’:
a.c:31:2: error: stray ‘\302’ in program
a.c:31:2: error: stray ‘\240’ in program
a.c:32:2: error: stray ‘\302’ in program
a.c:32:2: error: stray ‘\240’ in program
a.c:33:2: error: stray ‘\302’ in program
a.c:33:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:48:1: error: stray ‘\302’ in program
a.c:48:1: error: stray ‘\240’ in program
a.c:48:1: error: stray ‘\302’ in program
a.c:48:1: error: stray ‘\240’ in program
a.c:48:1: error: stray ‘\302’ in program
a.c:48:1: error: stray ‘\240’ in program
a.c:48:1: error: stray ‘\302’ in program
a.c:48:1: error: stray ‘\240’ in program
a.c:48:1: error: stray ‘\302’ in program
a.c:48:1: error: stray ‘\240’ in program
a.c:59:1: error: stray ‘\302’ in program
a.c:59:1: error: stray ‘\240’ in program
a.c:59:1: error: stray ‘\302’ in program
a.c:59:1: error: stray ‘\240’ in program
a.c:59:1: error: stray ‘\302’ in program
a.c:59:1: error: stray ‘\240’ in program
a.c:59:1: error: stray ‘\302’ in program
a.c:59:1: error: stray ‘\240’ in program
a.c:59:1: error: stray ‘\302’ in program
a.c:59:1: error: stray ‘\240’ in program
a.c: In function ‘boundaryfill4’:
a.c:61:2: error: stray ‘\302’ in program
a.c:61:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:71:1: error: stray ‘\302’ in program
a.c:71:1: error: stray ‘\240’ in program
a.c: In function ‘mulmat’:
a.c:73:2: error: stray ‘\302’ in program
a.c:73:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:84:1: error: stray ‘\302’ in program
a.c:84:1: error: stray ‘\240’ in program
a.c:84:1: error: stray ‘\302’ in program
a.c:84:1: error: stray ‘\240’ in program
a.c:84:1: error: stray ‘\302’ in program
a.c:84:1: error: stray ‘\240’ in program
a.c:91:1: error: stray ‘\302’ in program
a.c:91:1: error: stray ‘\240’ in program
a.c: In function ‘makeIdentity’:
a.c:93:2: error: stray ‘\302’ in program
a.c:93:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:101:1: error: stray ‘\302’ in program
a.c:101:1: error: stray ‘\240’ in program
a.c:101:1: error: stray ‘\302’ in program
a.c:101:1: error: stray ‘\240’ in program
a.c:101:1: error: stray ‘\302’ in program
a.c:101:1: error: stray ‘\240’ in program
a.c:101:1: error: stray ‘\302’ in program
a.c:101:1: error: stray ‘\240’ in program
a.c: In function ‘rotate’:
a.c:103:2: error: stray ‘\302’ in program
a.c:103:2: error: stray ‘\240’ in program
a.c: At top level:
a.c:113:1: error: stray ‘\302’ in program
a.c:113:1: error: stray ‘\240’ in program
a.c: In function ‘main’:
a.c:115:2: error: stray ‘\302’ in program
a.c:115:2: error: stray ‘\240’ in program
a.c:116:2: error: stray ‘\302’ in program
a.c:116:2: error: stray ‘\240’ in program
a.c:156:2: error: stray ‘\302’ in program
a.c:156:2: error: stray ‘\240’ in program
hey how to deal with this ???
@Rats These errors occurs due to presence of some non-ASCII characters in the code. These might have crept in accidently while copying it from some where. Check your program for non-ASCII characters by creating dump of the file using the command
ReplyDeleteod -c filename.c (return)
Non-ASCII characters are displayed as escape sequences in the dump file. You can redirect the dump output from the terminal to a file using the command
od -c filename.c>filename (return)
I tried to install libgraph-1.0.2 on ubuntu.the package guile-1.8-dev couldnt get installed.so i tried the command apt-get update.but it doesnt work at all.can you suggest any solution?
ReplyDelete@Ketaki : Did you try the "sudo apt-get update" command or just the "apt-get update". Use sudo command to execute a command as a superuser if you didn't do so.
ReplyDeleteIf it doesn't work, post the messages displayed on the terminal while trying the apt-get update command and during installing the package guile-1.8-dev.
You can also install the packages or update the system using the "Synaptic Package Manager". Just type "guile" in the search box and it will display the list of packages. Mark the required packages for installation and click on apply. After that, follow the on-screen instructions.
I tried to install the package as u said..but the following error occured :-
DeleteW: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gmp/libgmp3-dev_4.3.2+dfsg-1ubuntu3_amd64.deb
403 MediaTypeBlocked
W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gmp/libgmp3-dev_4.3.2+dfsg-1ubuntu3_amd64.deb
403 MediaTypeBlocked
also when I tried the command sudo apt-get update I got this message:
Err http://us.archive.ubuntu.com natty-updates/restricted Sources
404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
can u please suggest further steps required ??
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
DeleteE: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
To resolve the above error, use the command:
$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo dpkg --configure -a
After running these commands try running the sudo apt-get update command.
Else you can try finding what's holding the lock by using the command:
sudo lsof | grep /var/lib/dpkg/lock
and kill it by using the "kill" command.
If it doesn't work, post the details here.
In case you want to install "ubuntu-restricted-extras" package use the command:
Delete$ sudo apt-get install ubuntu-restricted-extras
I got an error..
ReplyDelete./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory
how to solve it..may be set a directory path but how to set a path.
please help me.
@Vinod : Use the command after you have completed the installation of the package:
ReplyDeletesudo cp /usr/local/lib/libgraph.* /usr/lib
error during after somtime running program
ReplyDelete./a.out
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
a.out: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
help me..
@Vinod : Can you mail me the program? I haven't encountered this error yet.
ReplyDelete#include
ReplyDelete#include
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
circle(100,100,50);
while(!kbhit());
closegraph();
return 0;
}
after sometime minimum. 30 to 45 sec. press any key or move mouse then show this error..
vinod@vinod-Aspire-4720Z:~/cfiles$ gcc gra.c -lgraph
vinod@vinod-Aspire-4720Z:~/cfiles$ ./a.out
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
a.out: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted
vinod@vinod-Aspire-4720Z:~/cfiles$
hey did u find a solution for this problem?
Delete@Vinod: Post it on ubuntu forums (http://ubuntuforums.org/).
ReplyDeleteFollowing errors occured after trying the above commands
ReplyDeletesudo rm /var/lib/apt/lists/lock
rm: cannot remove `/var/lib/apt/lists/lock': No such file or directory
ketaki@ubuntu:~$ sudo rm /var/cache/apt/archives/lock
rm: cannot remove `/var/cache/apt/archives/lock': No such file or directory
ketaki@ubuntu:~$ sudo dpkg --configure -a
dpkg: dependency problems prevent configuration of guile-1.8-dev:
guile-1.8-dev depends on libgmp3-dev; however:
Package libgmp3-dev is not installed.
dpkg: error processing guile-1.8-dev (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
guile-1.8-dev
ketaki@ubuntu:~$ sudo lsof | grep /var/lib/dpkg/lock
lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/ketaki/.gvfs
Output information may be incomplete.
ketaki@ubuntu:~$ kill
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
ketaki@ubuntu:~$ sudo apt-get install ubuntu-restricted-extras
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
guile-1.8-dev : Depends: libgmp3-dev but it is not going to be installed
ubuntu-restricted-extras : Depends: ubuntu-restricted-addons but it is not going to be installed
Recommends: gstreamer0.10-plugins-ugly-multiverse but it is not going to be installed
Recommends: ttf-mscorefonts-installer but it is not going to be installed
Recommends: unrar but it is not going to be installed
Recommends: gstreamer0.10-plugins-bad-multiverse but it is not going to be installed
Recommends: libavcodec-extra-52 but it is not going to be installed
Recommends: libmp4v2-0 but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
Use the command:
ReplyDelete$ sudo apt-get -f install
Configure the dpkg using the command:
$ sudo dpkg --configure -a
and then install the restricted sources using the command:
$ sudo apt-get install ubuntu-restricted-extras
Try updating the package repositories:
$ sudo apt-get update
If the above steps don't work, try re-configuring the dpkg:
$ sudo dpkg-reconfigure -a
This will take some time. After this try update manager or update the repositories using the "sudo apt-get update" command.
As for kill, it is a command which requires options and parameters as you can see in its man page. It requires the signal number and the process id of the process to be killed. For details, view its man page.
NTVDM allows a 16-bit DOS program to execute on Windows. It is basically a DOS emulator.
ReplyDeleteWhat version of Win XP are you using: 32-bit or 64-bit? Try using a emulator (such as dosbox) to run your program. This might help.
You can also try replacing the ntvdm.exe file in system32 directory by the one on the windows CD. Or repair Windows using the Win Xp CD.
I installed all the packages successfully. I'm using ubuntu 11.04
ReplyDeleteBut when I ran and compiled my program, it gave the following message:
Unable to init SDL: Unable to open a console terminal
Please advise!
This is my code:
#include
#include
int main()
{
int gd= DETECT,gm;
initgraph(&gd,&gm,NULL);
line(50,50,200,200);
getch();
closegraph();
return 0;
}
Thanks shekhar. :) so far one of the display circle programs worked well.
ReplyDeleteCan I now delete the extracted folder or are the files used directly from there?
Also, will all in built functions in c will work here?
You can delete the extracted folder.
ReplyDeleteAll built-in functions in C will work here. Only the compiler is different. If you are asking whether all built-in functions available under Turbo C or Windows will work here, the answer is No. Some built-in functions won't work like clrscr() and some more.
Could you give me alternatives to the following functions?
Deletegetch()
clrscr()
Also, i am getting an error while compiling-
undefined reference to 'initgraph' or any graphics library function.
thanks
Instead of clrscr(), use the system call- system("clear") or system("tput clear") in your program.
Deletegetch() works after you install libgraph. If you want, you can use a function (Source: Google Search):
#include
#include
#include
int getch(void)
{
struct termios oldattr, newattr;
int ch;
tcgetattr( STDIN_FILENO, &oldattr );
newattr = oldattr;
newattr.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
return ch;
}
Also you can use the "ncurses" library.
Regarding your error "undefined reference to libgraph" while compiling, just make sure you are using the command:
Delete$ gcc pgm.c -lgraph
while you compile you program.
Hope this helps.
The includes in the above comment are:
Deletetermios.h
unistd.h
stdio.h
I get an error after i compile if i put the mouse over the window or enter a input value
ReplyDelete[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
DISK: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted
I get an error after i compile if i put the mouse over the window or enter a input value
ReplyDelete[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
DISK: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted
Help please my project due later i need it to run
how do i solve it?
i have been breaking my head alot with this issue..
ReplyDeletetried alot of blogs..
but thanks 2 u...it worked!!
thanku so mch!!
after compiling when i had tried to run one of a graphics program it accepts one value but it is not accepting any other value further and showing this error- 't: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
ReplyDeleteAborted'
please sir help to overcome this problem.
Call initgraph after receiving all the inputs from the keyboard.
Deletebut what should i do if i want to use a graphics function after receiving one input and before receiving more inputs?
DeleteThis comment has been removed by the author.
ReplyDeleteHi Shekhar,
DeleteNice blog...Thanks for your valuabe inputs..Works perfectly..I thought for drawing and graphics alone we have to use windows only...But Linux itself is too good..No more blue screen of TURBO C..
while typing the command ./configure, shows an error : permission denied.. is any solution for this ? plz rply.. thanx in adv...
ReplyDeleteJust check for the permission using the chmod command. You might not have the privilege to run this command on the system.
DeletePls help to fix following problem .../a.out
ReplyDeleteUnable to init SDL: No available video device
.Am getting this error when running program
Check whether SDL is installed on your system or not. If it's installed, try updating it or go for re-installation of the same.
DeleteI am having the same error. mine is ubuntu 13.04 on vmware...
Deletethanks .....for all answers .I am very thankful to you..it make the c graphics programing in ubuntu very easy for me............
ReplyDeleteVery Thanks Sir for these guidelines
ReplyDeleteCan you hepl me set text color?
ReplyDeleteI can't do it.
Thank you!
+1 this post for -
ReplyDeleteThe error “./a.out: error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory” can be solved by
sudo cp /usr/local/lib/libgraph.* /usr/lib
Package guile-1.8-dev is not available, but is referred to by another package.
ReplyDeleteThis may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Unable to locate package libsdl-image1.2
E: Couldn't find any package by regex 'libsdl-image1.2'
please help i am getting this error while performing step 2. i.e """sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev""
complete error :
Deleteadmin_syed@ubuntu:~$ sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'guile-1.8-dev' for regex 'guile-1.8'
Package guile-1.8-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Unable to locate package libsdl-image1.2
E: Couldn't find any package by regex 'libsdl-image1.2'
E: Unable to locate package libsdl-image1.2-dev
E: Couldn't find any package by regex 'libsdl-image1.2-dev'
E: Package 'guile-1.8-dev' has no installation candidate
hi,
ReplyDeleteI am trying to execute c graphics program on fedora..got following error ..plz help
[root@localhost libgraph-1.0.2]# gcc om.c -lgraph -o om
/usr/bin/ld: cannot find -lgraph
collect2: error: ld returned 1 exit status
[root@localhost libgraph-1.0.2]#
your blog is a very nice . magic tv apk
ReplyDelete