A
Antonio Rivas
Hello all.
I've got a problem of multiple definition in a program that at first
glance looks correct (I won't type the whole code, just the relevant one
and as examples since seems is a linkage problem):
main.cpp
========
using namespace std;
....
#include "myHeader.h" // This is the header that causes the problem
....
int main()
{
...
Function_in_myHeader();
...
}
myHeader.h
==========
#ifndef MYHEADER_H
#define MYHEADER_H
....
void Function_in_myHeader(void);
#endif
myHeader.cpp
============
....
#include "myHeader.h" // I suspect the problem is here
....
void Function_in_myHeader(void)
{
- do something -
}
As I said, this structure arises a multiple definition error of
Function_in_myHeader (also of other identifiers declared in myHeader.h)
The problem is that I need to include myHeader.h in myHeader.cpp because
when I remove it the compiler throws errors of undeclared identifiers.
I tried also compile the program embedding the line within #ifndef
#define #endif but the result is the same as if I remove the line: not
declared identifiers/functions errors arise.
I have no clue about what is wrong.
Btw, I use gcc with CodeBlocks frontend and the program is compiled as C++
Thank you in advanced.
I've got a problem of multiple definition in a program that at first
glance looks correct (I won't type the whole code, just the relevant one
and as examples since seems is a linkage problem):
main.cpp
========
using namespace std;
....
#include "myHeader.h" // This is the header that causes the problem
....
int main()
{
...
Function_in_myHeader();
...
}
myHeader.h
==========
#ifndef MYHEADER_H
#define MYHEADER_H
....
void Function_in_myHeader(void);
#endif
myHeader.cpp
============
....
#include "myHeader.h" // I suspect the problem is here
....
void Function_in_myHeader(void)
{
- do something -
}
As I said, this structure arises a multiple definition error of
Function_in_myHeader (also of other identifiers declared in myHeader.h)
The problem is that I need to include myHeader.h in myHeader.cpp because
when I remove it the compiler throws errors of undeclared identifiers.
I tried also compile the program embedding the line within #ifndef
#define #endif but the result is the same as if I remove the line: not
declared identifiers/functions errors arise.
I have no clue about what is wrong.
Btw, I use gcc with CodeBlocks frontend and the program is compiled as C++
Thank you in advanced.