The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL undeclared filename and apply_surface not working
Blackmantis


Joined: 01 Apr 2014
Posts: 2
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:

Code:

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

Code:

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:

Code:

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.
mr_tawan


Joined: 13 Jan 2014
Posts: 161
Looks like `filename` is not declared. Try adding :-

Code:
std::string filename = "some_image_file.png";


Just above the `IMG_Load()`.
SDL undeclared filename and apply_surface not working
Alberto Corona
Guest

On Tuesday, April 01, 2014 04:53:47 Blackmantis wrote:
Quote:
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

You are answering your own question, filename is undeclared meaning that it
has no value before you use c_str().

Quote:
SDL_Surface* optimizedImage = NULL;

loadedImage = IMG_Load( filename.c_str() );

Here, you use filename.c_str() without it actually being defined as a string
before converting it to a const char*

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Blackmantis


Joined: 01 Apr 2014
Posts: 2
No problems, thanks for getting back to me guys, I have it working now. I was just a bit surprised that the source code for the tutorial did not include that part from lesson 02.