I discovered a very weird compiler error this morning when working on
my gam. I noticed that I have a few small functions in a source file and thought I might as well make them inline, but then I got compiler errors from g++. And it's not on every function, it's only on some functions. So I was very
why g++ was accepting some functions as inline and some not. Here's a sample of the compiler errors (I was only getting this when linking all the object files):
Code:
g++ -o allacrost src/audio.o src/battle.o src/boot.o src/data.o src/engine.o src/global.o src/main.o src/map.o src/pause.o src/quit.o src/scene.o src/utils.o src/video/color.o src/video/coord_sys.o src/video/primative.o src/video/simpletext.o src/video/tgaread.o src/video/video.o -lm -lSDL -lGL -lGLU -lIL -lILUT -lSDL_mixer -llua -llualib
src/main.o(.text+0x9ee): In function `main':
: undefined reference to `hoa_engine::GameSettings::SetTimer()'
src/main.o(.text+0xa0a): In function `main':
: undefined reference to `hoa_engine::GameModeManager::GetTop()'
src/main.o(.text+0xa37): In function `main':
: undefined reference to `hoa_engine::GameSettings::UpdateTime()'
src/main.o(.text+0xa44): In function `main':
: undefined reference to `hoa_engine::GameModeManager::GetTop()'
src/quit.o(.text+0x701): In function `hoa_quit::QuitMode::Update(unsigned)':
: undefined reference to `hoa_engine::GameModeManager::PopAll()'
collect2: ld returned 1 exit status
make: *** [allacrost] Error 1
After changing the above functions to be inline, everything compiled fine. What's interesting though is that I have two functions, hoa_engine::GameModeManager::Pop() and hoa_engine::GameModeManager::PopAll(). g++ is fine with Pop() being inline, but not with PopAll(). Here's the source of those two small functions:
Code:
// Free the top mode on the stack and pop it off
inline void GameModeManager::Pop() {
if (game_stack.size() > 0) {
delete game_stack.back();
game_stack.pop_back();
}
}
// Pop off all game modes
void GameModeManager::PopAll() {
while (game_stack.size() > 0) {
delete game_stack.back();
game_stack.pop_back();
}
}
So does anyone know why this is happening? This isn't a critical problem for me since I can just get around it by not inlining the "bad" functions, but I'd like to know why this is happening. If you have any wisdom to share, please do