我最近深入研究了一些 SDL 教程,但在编译这个教程时遇到了困难,特别是使用 DevC++ 和 SDL 库: http ://lazyfoo.net/SDL_tutorials/lesson05/index.php
我收到这个特殊的错误:`filename' undeclared (first use this function) and it points to the filename.c_str()); 代码区域,以及编译日志中列出的其他一些区域。我还想调查未被识别的“apply_surface”。我已包含以下标题:
#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;
链接器选项包括基于我发现的具有相同问题的其他线程的建议,看来我并不孤单,但我还没有完全找到适用于我的代码的解决方案:
-lmingw32
-mwindows
-lSDLmain
-lSDL
-lSDL_mixer
-lSDL_image
-lSDL_ttf
-lstdc++
代码片段:
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)
等等等等
编译日志:
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
任何建议或意见,将不胜感激。我是整个 C++ 场景的又一个笨蛋新手,但这更像是一个学习实验,而不是其他任何东西。我只是喜欢构建一个基本的光线投射器,并且一直坚持让 hud 显示。