So I've been making a program for quite some time, and I've always just worked around this issue because the project wasn't too large, but I've recently been assigned a much larger project, and want to have more files and such. Anyways. Here's the rundown.
main.cpp
...
msg(hWnd);
...
msg.cpp
#pragma once
#include "stdafx.h"
#include "rsrc.h"
void msg(HWND hWnd)
{
MessageBox(hWnd, "Hey!", "It worked!", MB_OK);
}
msg.cpp is included in the project, but there's no #include "msg.cpp" in main.cpp. It's also just an example file for this thread. That's why it's a stupid function.
If I put #include "msg.cpp" in main.cpp then I get a linking error, "... already defined in main.obj"
error C3861: 'msg': identifier not found
The workaround I always used was just declaring functions as static in stdafx.cpp. That always worked the way I excepted them too... I'm not sure what the problem is here. The problem extends to global variables that I declare in header or other source files... very annoying.