[Day21~Day23] Static function in Headers Confusion

Before Day 21, all of the codes I followed with Casey can be compiled and built without much fuss on Visual Studio 2013.

On Day 21, just as Casey started to switch over to breaking up the project to compile EXE and DLL separately, I realized that I had a serious issue with my codes. "Static functions are declared but not defined" errors are everywhere when I started to touch the #includes.

I forgot when Casey separated Win32 specific codes and Handmade Hero codes apart, but I do know that Casey declared a lot of static functions (internally static functions) throughout the code.

How did Casey do it with static functions in header files?

EDIT:

I meant to ask about declaring static functions in the header files. The functions being declared are GameUpdateAndRender() and GameGetSoundSamples().

Does it have to do with how
1
#include "handmade.cpp"
works in a way such that the static functions defined there can be used in other CPP files, making static function definitions be accessible throughout the translation units?

Edited by Thompson Lee on
Take a look at the warnings casey disabled in the build command file. He explicitly disabled that warning I think.
That is a warning? It can't be...

I created a brand new C++ project, and created a static function declaration in the header, similar to Casey's GameUpdateAndRender function. VS didn't compile, saying that static function is declared but not defined.

It is the same error I am getting when I move around the codes for the #includes in the win32_handmade.cpp.
About which function is warning about? In which file it is defined? And where declared? How are you including files?
About which function is warning about?

GameUpdateAndRender and GameGetSoundSamples.


In which file it is defined?


handmade.cpp

And where declared?


handmade.h

How are you including files?

1
2
#include "win32_handmade.h"
#include "handmade.cpp"


It is located in main.cpp. I am guessing main.cpp is win32_handmade.cpp.

Edited by Thompson Lee on
'static' means 'local to translation unit', and so the function has 'internal linkage' and so the linker won't expose the name, and therefore won't be able to find the definition in the other object file.

The solution here is to remove 'static', it's not what you meant to communicate.
Ah I see. That fixes the #includes issue I was having.