Jump to content
  • Advertisement
Sign in to follow this  
James Miller

SDL undeclared filename and apply_surface not working

This topic is 2024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
 



	
		
			
				 
			
				<pre>
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)</pre>
			
		
	


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 newbie to the whole C++ scene, but this is more of a learning experiment than anything else.

 

Share this post


Link to post
Share on other sites
Advertisement

Well, you seem to have simply copy/pasted a few lines of code out of the working tutorial code.

 

Your main issue right now seems to be to read errors properly.

 

1)

The filename. You pasted a few lines from a function, which had parameter as a function argument. Obviously that argument is not here, so you have to declare filename yourself above the location where you access it. The compiler simply doesn't know what "filename" is (Hint: In the tutorial code it's a std::string)

 

2)

apply_surface is the same. It's a function defined in the tutorial code. You only copied lines calling that function. The compiler obviously does not know the function.

Simple solution: Copy also the apply_surface function and paste it above the main function.

Share this post


Link to post
Share on other sites

Well, you seem to have simply copy/pasted a few lines of code out of the working tutorial code.

 

Your main issue right now seems to be to read errors properly.

 

1)

The filename. You pasted a few lines from a function, which had parameter as a function argument. Obviously that argument is not here, so you have to declare filename yourself above the location where you access it. The compiler simply doesn't know what "filename" is (Hint: In the tutorial code it's a std::string)

 

2)

apply_surface is the same. It's a function defined in the tutorial code. You only copied lines calling that function. The compiler obviously does not know the function.

Simple solution: Copy also the apply_surface function and paste it above the main function.

 

Thankyou for your reply!

 

Have gotten the code to compile without error, however when I run the program, the exe window pops up for about 1 split second and then disappears instantly. Despite it being advised against, I've tried using system pause to keep it from disappearing but to no avail. Is there something wrong with how I'm setting the project up perhaps?

 

I've noticed this happens for a few of the tutorials on the site, but not all. The play sound/display images tutorials have worked fine.

Edited by James Miller

Share this post


Link to post
Share on other sites

To keep the window running you need to have a "main loop", a loop that keeps the program running. If you leave the main method your program ends. From the tutorial code it's this snippet:

 

bool quit = false;
//While the user hasn't quit
while( quit == false )
{
  //While there's events to handle
  while( SDL_PollEvent( &event ) )
  {
    //If the user has Xed out the window
    if( event.type == SDL_QUIT )
    {
      //Quit the program
      quit = true;
    }
  }
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!