Author Topic: Noob alert! SDL.h  (Read 8721 times)

Stoop Solo (OP)

  • Posts: 11
Noob alert! SDL.h
« on: February 03, 2012, 08:13:35 am »
Hi folks,

Having started getting to grips with C++, I've decided to start having a go at some Dingoo programming. I followed the instructions fom SiENcE's prebuild Dingux Toolchain for Windows v0.1, and managed to get the viewimage example to compile no problem.

However, when  come to compile my own little SDL test program (after altering the source and destination in the makefile), I run into an error, stating:

Quote
main.cpp:1:17: SDL.h no such file or directory
main.cpp:2:23: SDL_image.h no such file or directory

Of course, it is then followed by numerous other lines about SDL_Surface not being declared etc. The test program naturally compiles in Windows using CodeBlocks with no problems. I've checked the includes in the source code:
#include "SDL.h"
#include "SDL_image.h"


...and this is exactly how they are specified in the viewimage.c file, which compiles with no problem.

Pretty-please, can someone enlighten me as to what I might be doing wrong? Do I need further alterations to the makefile for C++ as opposed to C? I wanna make some games!  :)

Re: Noob alert! SDL.h
« Reply #1 on: February 03, 2012, 10:12:20 am »
Hi,
I believe you did not declare the sdl directory.
Try this:

# include "C: \ cygwin \ Dingux \ mipsel-linux-uclibc \ include \ SDL \ sdl.h"
Or try this line in the makefile:
INC = \ C: \ cygwin \ dingux \ mipsel-linux-uclibc \ include
INCS = $ {INC}-I $ {INC} / SDL

I program only on linux and I think much better.
[email protected]
User flpstr (old flpstrquerendoumdingoo!!!) forum dingoobr

Stoop Solo (OP)

  • Posts: 11
Re: Noob alert! SDL.h
« Reply #2 on: February 03, 2012, 06:20:57 pm »
Hey man, thanks for the reply.

I tried using the full path to SDL in the main and extra C++ files, and apart from it chastising me for using an MS-DOS style path, it did a bit better. Now, however, the compiler complains that SDL_SDL_stdinc.h cannot find iconv.h

Additionally, I'm really not sure why I need to specify the exact path in my source files, when the viewimage example provided compiles with no problems, and does not specify any path to SDL.h or SDM_image.h.\

Seems I have much ground to cover...

Stoop Solo (OP)

  • Posts: 11
Re: Noob alert! SDL.h
« Reply #3 on: February 03, 2012, 11:48:53 pm »
Okay, it seems that specifying the PROGRAM in the makefile as "main.cpp" rather than just "main" allowed it to build. I suppose that's rather obvious on reflection.

That's allowed it to build... something. Don't know what yet, as I need to transfer it to the dingoo. The build was oddly silent and deleted (or maybe moved) the main.cpp from the user directory, then left a .dge file in its place. It didn't delete the other .cpp files that the main.cpp included though, which I'm guessing means they need to be compiled and linked.

Perhaps it's time I read up on makefiles.

EDIT: scratch that, it didn't "build" anything. It seems it just renamed the .cpp file to .dge. I must admit am pretty stuck.  ???
« Last Edit: February 04, 2012, 04:20:58 am by Stoop Solo »

jagotu

  • Posts: 188
Re: Noob alert! SDL.h
« Reply #4 on: February 04, 2012, 08:14:02 am »
If you're using cygwin, then this should do the trick: http://sience.schattenkind.net/dingoo/Dingux_Toolchain_for_Windows.htm.
I mean Adding c:\cygwin\bin to your Windows PATH, running cygwin.bat etc.
Then your makefile must look like this:
Quote

TOOLCHAINDIR := /dingux
BINPATH := $(TOOLCHAINDIR)/bin
LIBPATH := $(TOOLCHAINDIR)/lib

ARCH := mipsel-linux-uclibc-
CC := ${BINPATH}/$(ARCH)gcc

INCLUDES := -I${TOOLCHAINDIR}/mipsel-linux-uclibc/include/SDL

CFLAGS += $(shell $(BINPATH)/sdl-config --cflags)
LDFLAGS += $(shell $(BINPATH)/sdl-config --libs)
« Last Edit: February 04, 2012, 08:17:09 am by jagotu »
Sorry guys for not caring about dingoonity lately. It was nice to be with you, and maybe I'll come back, but not now...

Stoop Solo (OP)

  • Posts: 11
Re: Noob alert! SDL.h
« Reply #5 on: February 06, 2012, 04:15:39 am »
If you're using cygwin, then this should do the trick: ...etc

Hi jagotu,

Thanks for the info. I had actually set up cygwin from the same link you provided. Followed the instructions, updated the path, etc. I even managed to get the "viewimage.c" example it provides to compile with no problem. I only seem to get problems when I try compiling a C++ program. If I compile a .c source, it finds the SDL headers, but if I compile a .cpp source, it says it cannot find SDL.h or SDL_image.h. Do I need to set up declarations in the makefile differently for a .cpp?

This is the quick c++ test I'm trying to compile, named main.cpp. It just fills the screen with some blue gradient stuff:
Code: [Select]
#include "SDL.h"
#include "SDL_image.h"

//initialize screen
SDL_Surface *screenbuffer = NULL;

//misc variables for general stuff
int swidth = 320;
int sheight = 240;
int looprun = 1;
int filloffset = 0;

int main ( int argc, char* args[] )
{

    //initialize SDL and create a screenbuffer surface
    SDL_Init (SDL_INIT_EVERYTHING);
    screenbuffer = SDL_SetVideoMode (swidth, sheight, 32, SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_FULLSCREEN );

while (looprun)
{

        //Some stuff to fill the background.
        SDL_LockSurface (screenbuffer);
        Uint32 *pixels = (Uint32 *)screenbuffer->pixels;
        int argh = swidth * sheight;
        int xfill = 0;
        int yfill = 0;
        for (int xall = 0; xall < argh; xall++)
        {
        pixels[ xfill + yfill ] = xfill+filloffset;
        if (xfill++ == swidth)
            {
            yfill = yfill + swidth;
                xfill = 0;
            }
        }

        filloffset = ( filloffset + 1 ) & 0xFF;


//let's checking events with me!!
        SDL_Event event;
        if( SDL_PollEvent (&event) )
        //There was an event
        {
//it was a key press. End the program loop this cycle.
            if( event.type == SDL_KEYDOWN ) looprun = 0;

        }


//refresh the screen buffer.
        SDL_UpdateRect (screenbuffer, 0, 0, swidth, sheight);

}


SDL_Quit();
return 0;
}


The cygwin tool chain is set up exactly as instructed. This is what I have in the makefile:

Code: [Select]
TOOLCHAINDIR := /dingux
BINPATH    := $(TOOLCHAINDIR)/bin
LIBPATH    := $(TOOLCHAINDIR)/lib

INCLUDES := -I${TOOLCHAINDIR}/mipsel-linux-uclibc/include/SDL

ARCH := mipsel-linux-uclibc-
CC := ${BINPATH}/$(ARCH)gcc
CFLAGS  := -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
LDFLAGS := -O2 -Wall $(shell $(BINPATH)/sdl-config --libs) -lSDL_gfx -lSDL_image
SOURCES := *.o

PROGRAM = main
TARGET := dingootest.dge
VERSION = 1.0

all: $(PROGRAM)
mv $(PROGRAM) $(TARGET)

clean:
rm -f $(TARGET) *.o *~

"Make" produces the following result:


Code: [Select]
# make
g++   -O2 -Wall -L/dingux/mipsel-linux-uclibc/lib -Wl,-rpath,/usr/lib -lSDL -lpthread -lSDL_gfx -lSDL_image  main.cpp   -o main
main.cpp:1:17: SDL.h: No such file or directory
main.cpp:2:23: SDL_image.h: No such file or directory
main.cpp:10: error: expected constructor, destructor, or type conversion before '*' token
main.cpp:10: error: expected `,' or `;' before '*' token
main.cpp: In function `int main(int, char**)':
main.cpp:25: error: `SDL_INIT_EVERYTHING' undeclared (first use this function)
main.cpp:25: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:25: error: `SDL_Init' undeclared (first use this function)
main.cpp:26: error: `screenbuffer' undeclared (first use this function)
main.cpp:26: error: `SDL_DOUBLEBUF' undeclared (first use this function)
main.cpp:26: error: `SDL_HWSURFACE' undeclared (first use this function)
main.cpp:26: error: `SDL_FULLSCREEN' undeclared (first use this function)
main.cpp:26: error: `SDL_SetVideoMode' undeclared (first use this function)
main.cpp:35: error: `SDL_LockSurface' undeclared (first use this function)
main.cpp:36: error: `Uint32' undeclared (first use this function)
main.cpp:36: error: `pixels' undeclared (first use this function)
main.cpp:36: error: expected primary-expression before ')' token
main.cpp:36: error: expected `;' before "screenbuffer"
main.cpp:54: error: `SDL_Event' undeclared (first use this function)
main.cpp:54: error: expected `;' before "event"
main.cpp:55: error: `event' undeclared (first use this function)
main.cpp:55: error: `SDL_PollEvent' undeclared (first use this function)
main.cpp:59: error: `SDL_KEYDOWN' undeclared (first use this function)
main.cpp:67: error: `SDL_UpdateRect' undeclared (first use this function)
main.cpp:73: error: `SDL_Quit' undeclared (first use this function)
make: *** [main] Error 1

Of course, the undeclared errors are to be expected, but I cannot understand what is causing the compiler not to find SDL.h or SDL_image.h, as they are declared in an identical way to the viewimage.c example, which compiles. Guess I've been too spoiled with Codeblocks, where one just presses "build".

Thanks for the responses thus far, this c++ noob is appreciative.

pcercuei

  • Posts: 1728
    • My devblog
Re: Noob alert! SDL.h
« Reply #6 on: February 06, 2012, 07:41:37 am »
#include <SDL.h>
#include <SDL_image.h>

Using quotes is only for including local files.

Plus, your INCLUDES variable is not needed, the path to SDL is already set by sdl-config actually.
« Last Edit: February 06, 2012, 07:44:23 am by Ayla »

Stoop Solo (OP)

  • Posts: 11
Re: Noob alert! SDL.h
« Reply #7 on: February 06, 2012, 08:11:42 am »
#include <SDL.h>
#include <SDL_image.h>

Using quotes is only for including local files.

Plus, your INCLUDES variable is not needed, the path to SDL is already set by sdl-config actually.

Hi Ayla,

I see. Thanks for that info. Oddly enough, the viewimage.c sample program uses quotes for the SDL includes, but I thought it worth trying. The first two lines of the aforementioned test program now read:
Quote
#include <SDL.h>
#include <SDL_image.h>
Unfortunately, the compiler still can't find SDL.h and SDL_image.h when I'm compiling a .cpp.

If in the source code I specify the full path to the SDL header files in question in the #include statements, the compiler will find them, but then it complains that it cannot find the header files they reference.

At what point in the proceedings should I pound my fists on the keyboard and yell "will you just compile, you piece of crap"?

pcercuei

  • Posts: 1728
    • My devblog
Re: Noob alert! SDL.h
« Reply #8 on: February 06, 2012, 08:27:27 am »
You need to define CXX to point to mipsel-linux-uclibc-g++ the same way you did with CC for mipsel-linux-uclibc-gcc. Look at the log, it tries to compile the file with your system g++.
« Last Edit: February 06, 2012, 08:29:21 am by Ayla »

Stoop Solo (OP)

  • Posts: 11
Re: Noob alert! SDL.h
« Reply #9 on: February 06, 2012, 06:20:43 pm »
Ohhh, now I get it. Defining CXX and also CXXFLAGS has allowed that test case to compile. I don't have my dingoo on-hand to test the result, but it has certainly put together a .dge file that is most definitely binary looking.

Now I'll try to work out my more complicated test that includes additional source files.

Thanks again guys, you've been immensely helpful with my initial forays into makefiles.