I was trying to use 2 .cpp files with 1 .h file but whenever I include the .h file in both .cpp files I get the "Multiple Definitions" error. So I made this to show my problem and yes I am aware thing.cpp never does anything but that still triggers the problem Also I use Code::Blocks and the GNU GCC Compiler if that helps.
main.cpp
#include <iostream>
#include <C:\0w0\Multiple file test\Hello_world.h>
#include <windows.h>
using namespace std;
int main()
{
A:
Sleep(500);
Hello();
x++;
if(x==5)
{
Sleep(500);
Hello();
return -1;
}
goto A;
}
thing.cpp
#include <iostream>
#include <C:\0w0\Multiple file test\Hello_world.h>
#include <windows.h>
using namespace std;
int thing()
{
A:
Sleep(500);
Hello();
x++;
if(x==5)
{
Sleep(500);
Hello();
return -1;
}
goto A;
}
hello_world.h
#ifndef Hello_World_H
#define Hello_World_H
#endif // Hello_World
int x=1;
using namespace std;
int Hello()
{
cout << x << endl;
return 69;
}
I expect it to work normally but it doesn't and I get these errors
obj\Debug\thing.o||In function 'Z5Hellov':|
C:\0w0\Multiple file test\Hello_world.h|7|multiple definition of 'Hello()'|
obj\Debug\main.o:C:\0w0\Multiple file test\Hello_world.h|7|first defined here|
obj\Debug\thing.o||In function 'Z5Hellov':|
C:\0w0\Multiple file test\Hello_world.h|7|multiple definition of 'x'|
obj\Debug\main.o:C:\0w0\Multiple file test\Hello_world.h|7|first defined here|
||error: ld returned 1 exit status|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
edit: I don't know how this is in any way close to that other question you guys said it is. So how do I make this work that's all I need to know