Mantis
Mantis

Reputation: 1

SDL undeclared filename and apply_surface not working

I've recently dived into some SDL tutorials, but am having difficulty compiling this one in particular using DevC++ with the SDL library: http://lazyfoo.net/SDL_tutorials/lesson05/index.php

I am getting this particular error: `filename' undeclared (first use this function) and it points to the filename.c_str() ); area of the code, as well as a few others listed in the compile log. I'd like to also investigate the "apply_surface" not being recognized as well. I have included the following headers:

#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include "SDL/SDL.h"
#include "quickcg.h"
#include "SDL/SDL_mixer.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_ttf.h"

using namespace QuickCG;

Linker options include suggestions based on other threads I've found with the same issue, it appears I'm not alone but I haven't quite found the solution that applies to my code yet:

-lmingw32
-mwindows
-lSDLmain
-lSDL
-lSDL_mixer
-lSDL_image
-lSDL_ttf
-lstdc++

CODE SNIPPET:

int main(int /*argc*/, char */*argv*/[])
{
    {
    SDL_Surface* title = NULL;
    SDL_Surface* hud = NULL;
    SDL_Surface* screen = NULL;
    SDL_Surface* loadedImage = NULL;
    SDL_Surface* optimizedImage = NULL;

    loadedImage = IMG_Load( filename.c_str() );

    if (loadedImage != NULL)
    {
        optimizedImage = SDL_DisplayFormat( loadedImage );
        SDL_FreeSurface( loadedImage );
        if( optimizedImage != NULL)

etc etc

COMPILE LOG:

Compiler: Default compiler
Building Makefile: "D:\Coding\Raycaster\Makefile.win"
Executing  make...
make.exe -f "D:\Coding\Raycaster\Makefile.win" all
g++.exe -c raycaster.cpp -o raycaster.o -I"D:/Coding/Dev-Cpp/lib/gcc/mingw32/3.4.2    
/include"  -I"D:/Coding/Dev-Cpp/include/c++/3.4.2/backward"  -I"D:/Coding/Dev-Cpp
/include/c++/3.4.2/mingw32"  -I"D:/Coding/Dev-Cpp/include/c++/3.4.2"  -I"D:/Coding
/Dev-Cpp/include"    -fexpensive-optimizations -O3 -mwindows

raycaster.cpp: In function `int SDL_main(int, char**)':
raycaster.cpp:117: error: `filename' undeclared (first use this function)
raycaster.cpp:117: error: (Each undeclared identifier is reported only once for
each function it appears in.)

raycaster.cpp:130: error: invalid conversion from `SDL_Surface*' to `int'
raycaster.cpp:133: error: `apply_surface' undeclared (first use this function)
raycaster.cpp:134: error: `hud' undeclared (first use this function)

make.exe: *** [raycaster.o] Error 1

Execution terminated

Any suggestions or advice would be greatly appreciated. I'm yet another dumbo newbie to the whole C++ scene, but this is more of a learning experiment than anything else; I'd just love to build a basic raycaster and am stuck getting the hud to display.

Upvotes: 0

Views: 464

Answers (1)

jpw
jpw

Reputation: 44871

First: why did you comment out parts of the main function int main(int /*argc*/, char */*argv*/[])??? it should look like this: int main(int argc, char *argv[])

Second: unless you have declared the filenamevariable in the global scope before main (which the error suggests that you haven't) you need to declare it and provide a value for it. Since you're using the .c_str()method on it filenameshould probably be a str::string. Try adding this before the IMG_Load line:

std::string filename = "path to your file here";

If you want to know what is wrong with the rest of the code you have to post it too.

Upvotes: 0

Related Questions