benwad
benwad

Reputation: 6594

Linker error when declaring a function just before calling it

I've got an update function in my game that contains the following code:

void DrawMiniFPSCounter();
DrawMiniFPSCounter();

The DrawMiniFPSCounter() function is declared in a file called miniFPSCounter.cpp, which is part of the build target (I'm using Xcode). When building, I get a linker error saying that the DrawMiniFPSCounter symbol cannot be found. I've tried removing the declaration above and just calling DrawMiniFPSCounter() but that results in a 'symbol not found' error during compilation. Why would the linker have trouble finding this symbol? Is it something to do with the order in which symbols are resolved in the project?

EDIT: I ran the command nm hrMiniFPSCounter.o | grep Draw in my build directory, and got the following output:

00000000 T __Z15DrawMiniCounteriiiii
0002d040 S __Z15DrawMiniCounteriiiii.eh
00000a00 T __Z18DrawMiniFPSCounterv
0002d148 S __Z18DrawMiniFPSCounterv.eh
00000560 t __ZL9DrawDigitiiib
0002d128 s __ZL9DrawDigitiiib.eh

is this normal? Why the extra characters on the end of the function names?

Upvotes: 0

Views: 98

Answers (1)

stackdaemon
stackdaemon

Reputation: 349

In my experience most common "errors":

  1. Was the file (really) compiled?
  2. Was it (really) linked correctly?
  3. Did you give the function the name you thought you did?
  4. new Namespace issues :)

Are you sure that the miniFPSCounter.cpp file is compiled (/have been incouded in the project in the right way)? I guess what you are experiencing could be caused by a few different things,but in lack of more information I would say: Try to make sure that the cpp file is being compiled (maybe introduce a few syntax errors which would give rise to a compilation error if it is indeed compiled) and when you are sure about that, you can start checking for other stuff (suchas that it is being linked correctly, etc)

Edit: Putting checklist on top.

Upvotes: 1

Related Questions