Hello again, good people. I return, cap in hand, hoping for enlightenment from those with considerably more experience than I. Which would probably be all of you.
After getting a test SDL cpp application to compile and run on dingux, I wanted to move to the next stage and try compiling a cpp program with more than one source file. As this post might allude, it is not meeting with success.
Basically, I took my test program (which worked), and split the screen fill from the main.cpp to a function in a separate source, testlink.h/testlink.cpp. The result compiles and runs in codeblocks. I then took the sources and header into the cygwin toolchain and modified the makefile.
The compiler seems to build the .o files with no problem, and seems to link them at the end, but the resulting .dge file seems to just crash on dingux. It looks like it sets the screen mode, and I briefly see the black SDL mouse pointer, so I'm assuming the problem occurs when it tries to access the function in testlink and that I haven't done the linking properly in the makefile. Please could someone enlighten me as to the terrible noob error have I committed?
Here are the sources, header and makefile I'm using for this test:
main.cpp
#include <SDL.h>
#include <SDL_image.h>
#include "testlink.h"
//initialize screen
SDL_Surface *screenbuffer = NULL;
//misc variables for general stuff
int swidth = 320;
int sheight = 240;
int looprun = 1;
int filloff = 0;
int main ( int argc, char* args[] )
{
//initialize SDL and create a screenbuffer surface
SDL_Init (SDL_INIT_EVERYTHING);
screenbuffer = SDL_SetVideoMode (swidth, sheight, 0, SDL_ANYFORMAT | SDL_FULLSCREEN );
while (looprun)
{
//Some stuff to fill the background.
SDL_LockSurface (screenbuffer);
Uint32 *pixels = (Uint32 *)screenbuffer->pixels;
fillscreen ( pixels, swidth, sheight, filloff );
filloff = ( filloff + 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;
}
testlink.h
#ifndef TESTLINK_H_INCLUDED
#define TESTLINK_H_INCLUDED
void fillscreen ( Uint32* pixelarray, int canwidth, int canheight, int filloffset );
#endif // TESTLINK_H_INCLUDED
testlink.cpp
#include "SDL.h"
#include "testlink.h"
void fillscreen ( Uint32* pixelarray, int canwidth, int canheight, int filloffset )
{
int xfill = 0;
int yfill = 0;
int buffersize = canwidth * canheight;
for (int xall = 0; xall < buffersize; xall++)
{
pixelarray[ xfill + yfill ] = xfill+filloffset;
if (xfill++ == canwidth)
{
yfill = yfill + canwidth;
xfill = 0;
}
}
return;
}
and finally, 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
CXX := ${BINPATH}/$(ARCH)g++
CFLAGS := -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
CXXFLAGS:= -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
LDFLAGS := -O2 -Wall $(shell $(BINPATH)/sdl-config --libs) -lSDL_gfx -lSDL_image
all:
$(CXX) $(CXXFLAGS) -mips32 $(INCLUDES) -c testlink.cpp -o testlink.o
$(CXX) $(CXXFLAGS) -mips32 $(INCLUDES) -c main.cpp -o main.o
$(CXX) testlink.o main.o $(LDFLAGS) -o dingoolink.dge