当我尝试使用异常时获取名称错误[CodeBlocks,C ++]

时间:2012-09-02 08:51:54

标签: c++ exception name-mangling

我第一次尝试使用例外 但即使这是一个非常简单的例子我 只是无法让它编译,我看了 在几个例子中并尝试编码 许多不同的方式 但我还是不确定到底在哪里 问题是因为我得名字 当我介绍catch / try / throw时 这是我的代码,希望它是一些东西 真的很愚蠢:)

#include "Surface.h"
#include "SDL_Image.h"

using namespace std;

SDL_Surface* surface::Load(string fileName){

   SDL_Surface* loadedSurface = IMG_Load(fileName.c_str());
   if(loadedSurface == 0) throw 0;

   //Convert surface to same format as display
   loadedSurface = SDL_DisplayFormatAlpha(loadedSurface);

   return loadedSurface;
}

#include "GameState.h"
#include "Surface.h"

#include<iostream>

using namespace std;

GameState::GameState(string fileName){

   try{
      stateWallpaper_ = surface::Load(fileName);
   }
   catch(int& e){
      cerr << "Could not load " << fileName << endl;
   }
}

提前感谢您的帮助!

编辑:抱歉,我忘了发布错误消息:它是

In function `ZN14GameStateIntroC1Ev':|
-undefined reference to `__gxx_personality_sj0'|
-undefined reference to `_Unwind_SjLj_Register'|
-undefined reference to `_Unwind_SjLj_Unregister'|
In function `ZN14GameStateIntroC1Ev':|
undefined reference to `_Unwind_SjLj_Resume'|
In function `ZN14GameStateIntroC2Ev':|
-undefined reference to `__gxx_personality_sj0'|
-undefined reference to `_Unwind_SjLj_Register'|
-undefined reference to `_Unwind_SjLj_Unregister'|
obj\Release\GameStateIntro.o||In function `ZN14GameStateIntroC2Ev':|
C:\Program Files (x86)\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ext\new_allocator.h|69|undefined reference to `_Unwind_SjLj_Resume'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `redirect_output':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|219|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|220|undefined reference to `SDL_strlcat'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|243|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|244|undefined reference to `SDL_strlcat'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `console_main':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|296|undefined reference to `SDL_strlcpy'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|301|undefined reference to `SDL_GetError'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|312|undefined reference to `SDL_SetModuleHandle'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `WinMain@16':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|354|undefined reference to `SDL_getenv'|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|386|undefined reference to `SDL_strlcpy'|
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `cleanup':|
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|158|undefined reference to `SDL_Quit'|

**

1 个答案:

答案 0 :(得分:0)

从您的错误消息中,问题与任何方式的异常无关,而是与您的链接有关。您正在使用SDL标头但未链接到SDL库,请使用正确的-L选项。