Pages

Wednesday, August 25, 2010

C Graphics Programming in Ubuntu

-->
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.

94 comments:

  1. some error occurring while installing .....so I am unable to use it.
    kindly guide me....

    ReplyDelete
  2. Pls mention the error details u r getting....

    ReplyDelete
  3. bresen.o: ../../src/xcb_io.c:249: process_responses: Assertion `(((long) (dpy->last_request_read) - (long) (dpy->request)) <= 0)' failed.
    Aborted

    I get this message and the graph closes. Please help!
    email:whisperingwind.sanjay@gmail.com

    ReplyDelete
  4. In turbo c++, i use :
    int gdriver=detect,gmode,errorcode;
    initgraph(&gdriver,&gmode,"C:\\tcplus\\BGI");

    so whats the equivalent code here??

    ReplyDelete
  5. libgraph is so much equivalent to Turbo C++. It had been introduced keeping in view the users comfortable with Turbo C++.
    Simply 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.

    ReplyDelete
  6. 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.
    Just 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.

    ReplyDelete
  7. hi 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.


    one more thing,,when i used conio.h its showing me error ---->no such file or directory<----

    plzz help me get out of this ,,,chetan

    ReplyDelete
  8. conio.h is not available under libgraph...so just don't use it....
    use 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;
    }

    ReplyDelete
  9. first include is stdio.h and the 2nd one is graphics.h...

    ReplyDelete
  10. thank u shekar its working fine. i didn't expect such a quick repl from u,really thank u man.

    ReplyDelete
  11. why should we use gcc filename.c -lgraph for compiling
    isn't cc filename.c enough???(of course i did not get output using that command)
    just clarify me, thanks in advance

    ReplyDelete
  12. gcc filename.c -lgraph is used to link the program with libgraph which contains graphics.h .
    cc 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 ".

    ReplyDelete
  13. i get the following errors while installing >>>>>Makefile:934: warning: overriding commands for target `libgraph.pc'
    Makefile: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

    ReplyDelete
  14. Make sure you have you have installed build-essential and run the configuration command again.

    ReplyDelete
  15. hi shekhar..i followed the steps and its working...thanks a lot!!! it ws xtremely helpful!!!

    ReplyDelete
  16. SDl window is small sized. How to get 640*480 graphics mode

    ReplyDelete
  17. For 640*480 graphics mode, use the program statement:
    int 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.

    ReplyDelete
  18. When I am trying to compile file I got these errors
    /tmp/ccJKVMEj.o: In function `main':
    graph.c:(.text+0x11): undefined reference to `grprintf'
    collect2: ld returned 1 exit status

    ReplyDelete
  19. @Jayendra... Please post your program here. There's no problem related to the installation.

    ReplyDelete
  20. thanks for grate blog

    can we change then name of a.out
    like if program is for circle then we can call circle.out
    somthing

    ReplyDelete
  21. @GURU ... For that, you need to compile the program using the command:
    gcc 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.

    ReplyDelete
  22. /usr/bin/ld: cannot find -lgrpah
    collect2: ld returned 1 exit status

    i am encountering this error while compiling

    ReplyDelete
  23. @aryan
    It's "-lgraph" not "-lgrpah"

    ReplyDelete
  24. I still get an error when running the program:
    .. / .. / 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

    ReplyDelete
  25. @Situkangsayur..
    I 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.

    ReplyDelete
  26. used your sample code:
    #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

    ReplyDelete
  27. Thanks a lot!! I was searching for it like hell.
    Thanks once again!!!

    ReplyDelete
  28. How to fill the rectangle with a color?
    and how to make delay's in gcc for graphics programs?

    ReplyDelete
  29. how to draw rectangles of different line-widths?

    ReplyDelete
  30. Refer the documentation provided for graphics programming on the internet or some nice books. You will find everything there.
    As 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.

    ReplyDelete
  31. gcc doesn't include the DOS.H file which is neccessary for the DELAY function. What to do now?

    ReplyDelete
  32. thanks a million sir , it worked for me too

    ReplyDelete
  33. this is my code
    #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

    ReplyDelete
    Replies
    1. R u execute this code in ubunto?
      If yes then u should include stdlib.h instead of conio.h
      and also return type of main() is int

      Delete
  34. @Nisha

    CIRC.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.

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. i get the following error.


    /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

    ReplyDelete
  37. @shyam.. Post your program here. Can tell only after I see the program.

    ReplyDelete
  38. i keep getting this error in the terminal while the graphic window is open, and it ultimately aborts the program.

    a.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.

    ReplyDelete
  39. @Soham - Initialize the graph after u have received the inputs.

    ReplyDelete
  40. fantastic post buddy.... helped a lot... thank you so much..

    ReplyDelete
  41. thanks buddy...

    but how to include "dos.h".
    its not available in the packages.
    do u have any way ???

    ReplyDelete
  42. 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.

    Delay and sleep functions can be used by including the "graphics.h" header file.

    ReplyDelete
  43. gcc a.c -lgraph
    a.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 ???

    ReplyDelete
  44. @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
    od -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)

    ReplyDelete
  45. 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
  46. @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.
    If 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.

    ReplyDelete
    Replies
    1. I tried to install the package as u said..but the following error occured :-
      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


      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 ??

      Delete
    2. 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?
      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.

      Delete
    3. In case you want to install "ubuntu-restricted-extras" package use the command:
      $ sudo apt-get install ubuntu-restricted-extras

      Delete
  47. I got an error..

    ./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.

    ReplyDelete
  48. @Vinod : Use the command after you have completed the installation of the package:

    sudo cp /usr/local/lib/libgraph.* /usr/lib

    ReplyDelete
  49. error during after somtime running program

    ./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..

    ReplyDelete
  50. @Vinod : Can you mail me the program? I haven't encountered this error yet.

    ReplyDelete
  51. #include
    #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$

    ReplyDelete
    Replies
    1. hey did u find a solution for this problem?

      Delete
  52. @Vinod: Post it on ubuntu forums (http://ubuntuforums.org/).

    ReplyDelete
  53. Following errors occured after trying the above commands
    sudo 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).

    ReplyDelete
  54. Use the command:
    $ 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.

    ReplyDelete
  55. I have install all above instruction. I compiled id gcc filename.c -lgraph
    and no error then run ./a.out but error coming ./a.out:error while loading shared libraries: libgraph.so.1: cannot open shared object file: No such file or directory.again i type the above command sudo cp /usr/local/lib/libgraph.* /usr/lib still i have error .The error is command not fond. Then tell me what i will do to run my program and how to see out put.

    ReplyDelete
  56. can u tell me what is the meaning of NTVDM CPU has encountered ILLEGAL instruction while i am doing graphics program in turbo c++ v3.0 in xp sp2.i have NVIDIA chipest and amd anthlon processor.

    Plz help me .its urgent

    ReplyDelete
    Replies
    1. NTVDM allows a 16-bit DOS program to execute on Windows. It is basically a DOS emulator.
      What 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.

      Delete
  57. I installed all the packages successfully. I'm using ubuntu 11.04
    But 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;
    }

    ReplyDelete
  58. Thanks shekhar. :) so far one of the display circle programs worked well.

    Can 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?

    ReplyDelete
  59. You can delete the extracted folder.

    All 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.

    ReplyDelete
    Replies
    1. Could you give me alternatives to the following functions?

      getch()
      clrscr()

      Also, i am getting an error while compiling-
      undefined reference to 'initgraph' or any graphics library function.

      thanks

      Delete
    2. Instead of clrscr(), use the system call- system("clear") or system("tput clear") in your program.

      getch() 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.

      Delete
    3. Regarding your error "undefined reference to libgraph" while compiling, just make sure you are using the command:
      $ gcc pgm.c -lgraph
      while you compile you program.

      Hope this helps.

      Delete
    4. The includes in the above comment are:
      termios.h
      unistd.h
      stdio.h

      Delete
  60. I get an error after i compile if i put the mouse over the window or enter a input value
    [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

    ReplyDelete
  61. I get an error after i compile if i put the mouse over the window or enter a input value
    [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?

    ReplyDelete
  62. i have been breaking my head alot with this issue..
    tried alot of blogs..
    but thanks 2 u...it worked!!
    thanku so mch!!

    ReplyDelete
  63. 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.
    Aborted'
    please sir help to overcome this problem.


    ReplyDelete
    Replies
    1. Call initgraph after receiving all the inputs from the keyboard.

      Delete
    2. but what should i do if i want to use a graphics function after receiving one input and before receiving more inputs?

      Delete
  64. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Hi Shekhar,

      Nice 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..

      Delete
  65. while typing the command ./configure, shows an error : permission denied.. is any solution for this ? plz rply.. thanx in adv...

    ReplyDelete
    Replies
    1. Just check for the permission using the chmod command. You might not have the privilege to run this command on the system.

      Delete
  66. Pls help to fix following problem .../a.out
    Unable to init SDL: No available video device
    .Am getting this error when running program

    ReplyDelete
    Replies
    1. 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.

      Delete
    2. I am having the same error. mine is ubuntu 13.04 on vmware...

      Delete
  67. thanks .....for all answers .I am very thankful to you..it make the c graphics programing in ubuntu very easy for me............

    ReplyDelete
  68. Very Thanks Sir for these guidelines

    ReplyDelete
  69. Can you hepl me set text color?
    I can't do it.
    Thank you!

    ReplyDelete
  70. +1 this post for -

    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

    ReplyDelete
  71. 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'


    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""

    ReplyDelete
    Replies
    1. complete error :
      admin_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

      Delete
  72. hi,
    I 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]#

    ReplyDelete