THEY'RE ANNOYING! :@

This is my code:

lang.h

#pragma once

#define _ASM_START namespace _TomAsm{
#define _ASM_END   }

#define cpp_asm _TomAsm

#define _main int main(){
#define _endmain }

_ASM_START
template<typename _T>
struct _Reg{
	_T val;
	_Reg(_T _Val):val(_Val){}
};

typedef _Reg<int> _IntReg;
typedef _Reg<char> _CharReg;
typedef _Reg<float> _FloatReg;
typedef _Reg<double> _DoubleReg;
_ASM_END

instructions.h:

#pragma once

#include "lang.h"
#include "registers.h"

_ASM_START
void imov(_IntReg _Register, int _Val      );
void cmov(_CharReg _Register, char _Val    );
void fmov(_FloatReg _Register, float _Val  );
void dmov(_DoubleReg _Register, double _Val);

void iadd(_IntReg _Register, int _Val      );
void cadd(_CharReg _Register, char _Val    );
void fadd(_FloatReg _Register, float _Val  );
void dadd(_DoubleReg _Register, double _Val);

void isub(_IntReg _Register, int _Val      );
void csub(_CharReg _Register, char _Val    );
void fsub(_FloatReg _Register, float _Val  );
void dsub(_DoubleReg _Register, double _Val);

void iout();
void mcout();
void fout();
void dout();
_ASM_END

instructions.cpp:

#include <iostream>
#include "lang.h"
#include "instructions.h"
#include "registers.h"
using namespace std;
using namespace _TomAsm;

void _TomAsm::imov(_IntReg _Register, int _Val)
{_Register.val = _Val;}

void _TomAsm::cmov(_CharReg _Register, char _Val)
{_Register.val = _Val;}

void _TomAsm::fmov(_FloatReg _Register, float _Val)
{_Register.val = _Val;}

void _TomAsm::dmov(_DoubleReg _Register, double _Val)
{_Register.val = _Val;}

void _TomAsm::iadd(_IntReg _Register, int _Val)
{_Register.val += _Val;}

void _TomAsm::cadd(_CharReg _Register, char _Val)
{_Register.val += _Val;}

void _TomAsm::fadd(_FloatReg _Register, float _Val)
{_Register.val += _Val;}

void _TomAsm::dadd(_DoubleReg _Register, double _Val)
{_Register.val += _Val;}

void _TomAsm::isub(_IntReg _Register, int _Val)
{_Register.val -= _Val;}

void _TomAsm::csub(_CharReg _Register, char _Val)
{_Register.val -= _Val;}

void _TomAsm::fsub(_FloatReg _Register, float _Val)
{_Register.val -= _Val;}

void _TomAsm::dsub(_DoubleReg _Register, double _Val)
{_Register.val -= _Val;}

void _TomAsm::iout()
{ cout << eax.val; }

void _TomAsm::mcout()
{ cout << EAX.val; }

void _TomAsm::fout()
{ cout << ecx.val; }

void _TomAsm::dout()
{ cout << ECX.val; }

registers.h:

#pragma once

#include "lang.h"
_ASM_START
_IntReg eax(0), ebx(0);
_CharReg EAX('?'), EBX('?');
_FloatReg ecx(0.0f), edx(0.0f);
_DoubleReg ECX(0.0), EDX(0.0);
_ASM_END

main.cpp:

#include "instructions.h"
#include "lang.h"
using namespace cpp_asm;

_main
	imov(eax, 0);
	iadd(eax, 4);
	isub(eax, 1);
	iout();
_endmain

I get these errors, even though I have put #pragma once in all the .h files:

------ Build started: Project: c++ AND asm, Configuration: Debug Win32 ------
Compiling...
main.cpp
Generating Code...
Compiling...
instructions.cpp
Generating Code...
Linking...
main.obj : error LNK2005: "struct _TomAsm::_Reg<int> _TomAsm::ebx" (?ebx@_TomAsm@@3U?$_Reg@H@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<double> _TomAsm::EDX" (?EDX@_TomAsm@@3U?$_Reg@N@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<float> _TomAsm::edx" (?edx@_TomAsm@@3U?$_Reg@M@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<double> _TomAsm::ECX" (?ECX@_TomAsm@@3U?$_Reg@N@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<float> _TomAsm::ecx" (?ecx@_TomAsm@@3U?$_Reg@M@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<int> _TomAsm::eax" (?eax@_TomAsm@@3U?$_Reg@H@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<char> _TomAsm::EAX" (?EAX@_TomAsm@@3U?$_Reg@D@1@A) already defined in instructions.obj
main.obj : error LNK2005: "struct _TomAsm::_Reg<char> _TomAsm::EBX" (?EBX@_TomAsm@@3U?$_Reg@D@1@A) already defined in instructions.obj
C:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\c++ AND asm\Debug\c++ AND asm.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\c++ AND asm\c++ AND asm\Debug\BuildLog.htm"
c++ AND asm - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have no idea why I am getting these errors, it's not making any sense.

Can someone help me to fix these linker errors

Any help would be appreciated :)

>linker errors... I HATE THEM
The I HATE THEM -part really was too much for me, first: it adds no more extra information about your program (in other words: it's not meaningful), second: I really hate uppercase letters, especially in titles, so I've changed the title of this post as well.

Read this, maybe something useful for you:
http://www.catb.org/~esr/faqs/smart-questions.html#bespecific

>THEY'RE ANNOYING! :@
Another example of useless information, it won't help us, nor will it help you.
(Also, because it's in uppercase it seems like you're screaming, yelling, etc...)

>I have no idea why I am getting these errors, it's not making any sense.
Only by looking at the error messages I would say that you've (re)defined the same thing multiple times.

But I can't see where I have defined them more than once, I've only defined them in registers.h, and that's got a #pragma once in it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.