c graphics

Asked by prasad.ram on 2011-02-17

how can i do c graphics in ubuntu i installed graphics header files
and i have a example program

#include "SDL.h" // main SDL header

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define COLORKEY 255, 0, 255 //Your Transparent colour

SDL_Surface *screen; //This pointer will reference the backbuffer

int InitVideo(Uint32 flags = SDL_DOUBLEBUF | SDL_FULLSCREEN) {
 // Load SDL
 if (SDL_Init(SDL_INIT_VIDEO) != 0) {
   fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
   return false;
 }
 atexit(SDL_Quit); // Clean it up nicely :)

 // fullscreen can be toggled at run time :) any you might want to chang
ags with params?
 //set the main screen to SCREEN_WIDTHxSCREEN_HEIGHT with a colour depth

 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags);
 if (!screen) {

  fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
      return false;
      }
      return true;
     }
and it gives error like

"gra.cpp:2: fatal error: SDL.h: No such file or directory
compilation terminated."
how can i remove this error please tell me

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Last query:
2011-02-24
Last reply:
2011-02-24
mycae (mycae) said : #1

Your compilation line is wrong, or you can alter the include paths; I think I mentioned this before.

Note in the libsdl1.2-dev package:
http://packages.ubuntu.com/maverick/amd64/libsdl1.2-dev/filelist

The second line is:
/usr/include/SDL/SDL.h

Which means that this file is in /usr/include/SDL/SDL.h

Unless you instruct GCC to do otherwise with the -I/PATH/TO/INCLUDES/ (note that is a capital i, not a lowercase L)., it will look in /usr/include for include files.

So your command is asking it to look for /usr/include/SDL.h , which does not exist, as the true file is /usr/include/SDL/SDL.h

Either you can:
1) Alter the include paths by adding -I/usr/include/SDL/ to your compilation instructions (again that is captial eye, not lowercase ELL)
OR
2) modify #include "SDL.h" to #include "SDL/SDL.h"

prasad.ram (prasad-ram126) said : #2

i modified that #include"STD/STD.H" but it shows an error like
gra.c:9: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token and that 9th line
is shown below
"int InitVideo(Uint32 flags = SDL_DOUBLEBUF | SDL_FULLSCREEN) " sir please
send me how can i remove it

On Fri, Feb 18, 2011 at 2:51 AM, mycae <<email address hidden>
> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> Your compilation line is wrong, or you can alter the include paths; I
> think I mentioned this before.
>
> Note in the libsdl1.2-dev package:
> http://packages.ubuntu.com/maverick/amd64/libsdl1.2-dev/filelist
>
> The second line is:
> /usr/include/SDL/SDL.h
>
> Which means that this file is in /usr/include/SDL/SDL.h
>
> Unless you instruct GCC to do otherwise with the -I/PATH/TO/INCLUDES/
> (note that is a capital i, not a lowercase L)., it will look in
> /usr/include for include files.
>
> So your command is asking it to look for /usr/include/SDL.h , which does
> not exist, as the true file is /usr/include/SDL/SDL.h
>
> Either you can:
> 1) Alter the include paths by adding -I/usr/include/SDL/ to your
> compilation instructions (again that is captial eye, not lowercase ELL)
> OR
> 2) modify #include "SDL.h" to #include "SDL/SDL.h"
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #3

try chaning "Uint32" to just "int"

prasad.ram (prasad-ram126) said : #4

i changed what you are said but of no use it gives same error like
gra.c:9: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token so what can i do

On Sun, Feb 20, 2011 at 12:27 AM, mycae <
<email address hidden>> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> try chaning "Uint32" to just "int"
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=2
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #5

The code you posted with the suggested modification compiles perfectly for me under lucid.

Thus what you have now is not what you posted.

prasad.ram (prasad-ram126) said : #6

i send my program and i changed what you are said that i.e "unit32" to "int
" it still gives the same error in same line
actually my problem is i want to run a simple graphic program in c in
ubuntu why because i would like to know is ubuntu support graphic for that
purpose i am checking if my program is wrong please send me a simple program

1 //#include <cstdlib> // For some useful functions such as atexit :)
      2 #include "SDL/SDL.h" // main SDL header
      3
      4 #define SCREEN_WIDTH 640
      5 #define SCREEN_HEIGHT 480
      6 #define COLORKEY 255, 0, 255 //Your Transparent colour
      7
      8 SDL_Surface *screen; //This pointer will reference the backbuffer
      9 int InitVideo(int flags = SDL_DOUBLEBUF | SDL_FULLSCREEN) {
     10 // Load SDL
     11 if (SDL_Init(SDL_INIT_VIDEO) != 0) {
     12 fprintf(stderr, "Unable to initialize SDL: %s\n",
SDL_GetError());
     13 return false;
     14 }
     15 atexit(SDL_Quit); // Clean it up nicely :)
     16
     17 // fullscreen can be toggled at run time :) any you might want to
change the flags with params?
     18 //set the main screen to SCREEN_WIDTHxSCREEN_HEIGHT with a colour
depth of 16:
     19 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags);
:set nu

On Sun, Feb 20, 2011 at 12:51 AM, mycae <
<email address hidden>> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> The code you posted with the suggested modification compiles perfectly
> for me under lucid.
>
> Thus what you have now is not what you posted.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=4
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #7

Stripping out the line numbers, that compiles. (but doesn't link).

adding an int main(){ }

makes it link. Your error is a compilation error, not a linker error, so thats irrelevant.

Are you 100% sure you installed libsdl-dev, as indicated in your previous question?

mycae (mycae) said : #8

Just to let you know, I saved the program to main.cpp (C++ technically).

then compiled it with:
g++ main.cpp -I/usr/include/SDL -lsdl -o main

mycae (mycae) said : #9

Ah, ok, I see the problem now, you have been using C, and I have been using C++.

Here is the same code in C:

#include <stdlib.h> // For some useful functions such as atexit :)
#include "SDL/SDL.h" // main SDL header

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define COLORKEY 255, 0, 255 //Your Transparent colour

SDL_Surface *screen; //This pointer will reference the backbuffer
int InitVideo(int flags) {
// Load SDL
 if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  fprintf(stderr, "Unable to initialize SDL: %s\n",
          SDL_GetError());
  return 1;
 }
 atexit(SDL_Quit); // Clean it up nicely :)

// fullscreen can be toggled at run time :) any you might want to change the flags with params?
//set the main screen to SCREEN_WIDTHxSCREEN_HEIGHT with a colour depth of 16:
 screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags);
}

int main(int argc, char*argv[])
{
 InitVideo(SDL_DOUBLEBUF | SDL_FULLSCREEN);
}

This code is compiled with::
gcc main.c -I/usr/include/SDL -lSDL -o main

prasad.ram (prasad-ram126) said : #10

i did not remember but i think i installed it any how can i check it please
tell me

On Mon, Feb 21, 2011 at 12:15 AM, mycae <
<email address hidden>> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> Stripping out the line numbers, that compiles. (but doesn't link).
>
> adding an int main(){ }
>
> makes it link. Your error is a compilation error, not a linker error, so
> thats irrelevant.
>
> Are you 100% sure you installed libsdl-dev, as indicated in your
> previous question?
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=6
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #11

sudo apt-get install libsdl-dev

prasad.ram (prasad-ram126) said : #12

i think i am installed that ok when i execute that command it gives the
result

"admin@ramki:~$ sudo apt-get install libsdl-dev
[sudo] password for admin:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libsdl1.2-dev' instead of 'libsdl-dev'
libsdl1.2-dev is already the newest version.
libsdl1.2-dev set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 290 not upgraded."
that means it already installed
so what is the problem
please tell me

On Tue, Feb 22, 2011 at 5:40 PM, mycae <<email address hidden>
> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> sudo apt-get install libsdl-dev
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=10
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #13

Yes, that is right -- have you tried compiling the program?

Do be aware that the program is just a shell for further work, whatever you have in mind.

prasad.ram (prasad-ram126) said : #14

actually i don't know what the program tells my purpose i want to is ubuntu
supports graphics through c programming if it works i want to learn graphics
in ubuntu for that purpose i am taking that program as a example but it
doesn't working if you know any simple program in graphics please send me
that my intention is is ubuntu supports graphics or not?

On Wed, Feb 23, 2011 at 7:21 AM, mycae <<email address hidden>
> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> Yes, that is right -- have you tried compiling the program?
>
> Do be aware that the program is just a shell for further work, whatever
> you have in mind.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=12
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #15

Thats as simple as it gets, I am afraid.

prasad.ram (prasad-ram126) said : #16

sir i did't understand what you are said that ?

On Thu, Feb 24, 2011 at 2:26 AM, mycae <<email address hidden>
> wrote:

> Your question #145781 on gcc-defaults in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> Status: Open => Answered
>
> mycae proposed the following answer:
> Thats as simple as it gets, I am afraid.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781/+confirm?answer_id=14
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gcc-defaults/+question/145781
>
> You received this question notification because you are a direct
> subscriber of the question.
>

mycae (mycae) said : #17

The program I have demonstrated creates a drawing canvas using the SDL library. This allows access to direct drawing routines on the screen.
https://secure.wikimedia.org/wikipedia/en/wiki/Simple_DirectMedia_Layer

The program shown above, both the C and C++ versions, are so-called "minimal" examples. If they work, then your computer is ready to be instructed in whatever you want it to do. I cannot provide you with any simpler instructions -- anything more simple just won't have the needed instructions to tell the computer what to do.

You need to provide the instructions, and need to read the documentation as to how those instructions are supplied.

There are extensive guides on using SDL, and people (including myself) have used the library quite successfully.

If you are unfamiliar with C then you may wish to read some more tutorials on how to do simple tasks, like troubleshooting compiler errors, how the compiler finds external resources, such as header files, and what the difference between the compile and link stages are.

Can you help with this problem?

Provide an answer of your own, or ask prasad.ram for more information if necessary.

To post a message you must log in.