红联Linux门户
Linux帮助

graphics.h in Linux

发布时间:2008-08-05 00:17:54来源:红联作者:Ioonvme
For my Univ project, I need 2 use graphics.h. Everyone knows graphics.h is not in C's standard library. Only Turbo C supports it and for that I need 2 use windows all the time which I don't like. So I had 2 find an alternate way of doing it and libgraph was just the thing I needed most. 'libgraph' is mainly a wrapper around SDL's libraries that effectively provides most of the functions of graphics.h.

Here is how I set up libgraph in my Debian Sid:

Downloaded the latest version of libgraph from this site:

http://download.savannah.nongnu.org/releases/libgraph/

First installed some libraries that libgraph depends on:

#apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev

(if you are using other distros like Fedora or Suse, packages 4 these distros are also avalable)

Extarcted the tarball

$tar xvzf libgraph-1.0.2.tar.gz

Then inside the folder ran this:

$./configure
$make
#make install

The default destination for the shared library files is /use/local/lib, if this path is not included in your library path (mine was not) then u have to add that manually in your /etc/ld.so.conf

Our installation is complete now. Now I make a simple test.c with these codes:

#include stdio.h
#include graphics.h

int main(void)
{
int gd=DETECT, gm=VGAMAX;
initgraph(&gd, &gm, 0);
moveto(0, 0);
rectangle(50,50,500,200);
while (!kbhit());
closegraph();
return 0;
}

[Note: There seems 2 be some problem when I try to put stdio.h inside angled brackets so I'm writing that normally]

Now when we need 2 compile this test.c file we need 2 provide '-lgraph' flag

$gcc test.c -o test.out -lgraph

Walla! I saw a black window with a rectangle in the middle.
Posted by Abu Zaher Md. Faridee at 11:43 PM

Labels: programming
文章评论

共有 1 条评论

  1. freeflyfish 于 2008-08-16 06:10:25发表:

    没试验就转阿,里面程序都是错的……

    initgraph(&gd, &gm, 0);

    改为

    initgraph(&gd, &gm, 0);