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:

1
2
3
4
5
6
7
8
9
#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:

[/code]
-lmingw32
-mwindows
-lSDLmain
-lSDL
-lSDL_mixer
-lSDL_image
-lSDL_ttf
-lstdc++
[/code]

CODE SNIPPET:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 newbie to the whole C++ scene, but this is more of a learning experiment than anything else.
Last edited on
It doesn't look like you have declared the filename variable so the compiler doesn't know what it is.

You'll have to declare it before you can use it.
1
2
std::string filename = "foo.png"
loadedImage = IMG_Load( filename.c_str() );


Or you could just pass the filename directly.
 
loadedImage = IMG_Load("foo.png");


The apply_surface function is introduced in lesson 2. http://lazyfoo.net/SDL_tutorials/lesson02/index.php
To be able to use it you have to put it in your code.
Thanks for getting back to me, all fixed up now! Alas I had forgotten to include it from the earlier tutorial. Serves me right for being a copy-paste junkie though.
Topic archived. No new replies allowed.