Nusrat Nuriyev
asked on
Understanding of redefinition compiler error and multiple definition error.
My question is about to learn some preventive knowledges about redefinition/multiple definition compiler error.
Actually, when I get them - really get lost.
Also what about object files, executable and a bit more information about what does linker.
The good answer is those which is able to visually demonstrate the job of linker.
I know that, linker gathers objects together, and creates an executable. But that level of knowledge does not satisfy me.
It's too high level of abstraction. Need to see whole picture, but see in details.
Assuming that we are spearking in context of C programming language in Linux environment or Windows environment.
Actually, when I get them - really get lost.
Also what about object files, executable and a bit more information about what does linker.
The good answer is those which is able to visually demonstrate the job of linker.
I know that, linker gathers objects together, and creates an executable. But that level of knowledge does not satisfy me.
It's too high level of abstraction. Need to see whole picture, but see in details.
Assuming that we are spearking in context of C programming language in Linux environment or Windows environment.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
1.
2. Well, I have tried mutual inclusion, g++ compiler falls into an infinite loop. :)
3. Could you provide an example of "same 'object' code for function" compiler error?
4.
5. Can we say that object file == executable file with one exception that object file must not contain main function?
if you compile b.cpp the compiler would complain that function f has multiple definition because implementation (definition) of f was included twice by including a.h both in b.cpp and in b.h.Could we say, that there are two "levels" of redefinitions: at source code level and at object code level?
if b.cpp only would include b.h the compiler is happy. but if you include a.h or b.h in a.cpp, the linker would complain because it finds the same 'object' code for function f in b.obj (b.o in linux) and in a.obj.
2. Well, I have tried mutual inclusion, g++ compiler falls into an infinite loop. :)
3. Could you provide an example of "same 'object' code for function" compiler error?
4.
implementation must be provided by include files such that the compiler can create machine code for the concrete template type(s) you added in your source code. anyway, finally the object file contains all machine code from implementation of your source code.So, when I add
#include "stdio.h"
which object file is embedded to my object file?5. Can we say that object file == executable file with one exception that object file must not contain main function?
Could we say, that there are two "levels" of redefinitions: at source code level and at object code level?actually it is more a duplicate than a redefinition. the errors occur because either the compiler or the linker detect an ambiguous definition which they can't resolve. obviously the compiler can detect ambiguous definitions only in the source file it was compiling and the code of header files which have been included by the precompiler.
Well, I have tried mutual inclusion, g++ compiler falls into an infinite loop. :)bad. the precompiler should have a maximum include depth.
Could you provide an example of "same 'object' code for function" compiler error?
class X
{
void f();
};
void X::f()
{
...
}
void X::f()
{
...
}
the compiler error is 'X::f already has a body.'
Sara
ASKER
g++ -E b.cpp
Open in new window
Could you explain a little bit about the content of this output. What does all lines with # sign mean?