The global variable should be declared extern in a header file included by both source files, and then defined in only one of those source files:
common.h
extern int global;
source1.cpp
#include "common.h"
int global;
int function();
int main()
{
global=42;
function();
return 0;
}
source2.cpp
#include "common.h"
int function()
{
if(global==42)
return 42;
return 0;
}