Bit of a theoretical question (instead of a specific example) I thought I had understood this, but now I am having doubts again...
Scenario:
We have an common class called
bob
and its a header only implementation.We have a library (
lib1
) that uses bob (such that bob is defined in the compiled library).We also have an application (
exe1
) that uses bob (such that bob is defined in the compiled executable).
Now there is (afaik) a definition of bob
in both lib1
and exe1
. What happens if I try to link lib1
into exe1
... is that possible?
Is there any difference if I make the class bob
into a .cpp and .hpp pair of files and compile the cpp file in both the library and the exectuable - or is that basically the same thing?
My question really relates to what definitions are within the two binaries and what does the linker really do about all this? (the code being trivial). My understanding is that this should always cause a redefinition of bob
error, but I don't seem to be seeing this.
This could mean I am doing somthing wrong - so I wanted to confirm with you guys if what I believe is correct?