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