-
Linking problem
First I'd like to point out that the structure is kinda bad, so if you wanna flame me for it please don't :D.
Anyway, consider 3 files:
a.h:
Code:
#ifndef A_H
#define A_H
void Func()
{
...
}
#endif
(yes, that's a function definition in the header!)
b.cpp:
c.cpp:
b.cpp and c.cpp are compiled as separate modules then linked together. Now, even with inclusion guards in a.h the function will be defined in both files thus causing conflicts when linking b and c together.
I know I have a definition in the header file which I in all other cases would NOT do, but in this particular scenario it is required.
Is this solveable, to only get it defined once in one module? Or solve it in any other way? Since the modules are separately compiled the inclusion guards doesn't work well.
-
>> ...but in this particular scenario it is required.
Why are you "required" to do something you're not supposed to do?
Make it "inline void Func()".
gg
-
I'm making a header for a DLL I'm working on, and it needs a setup and a shutdown function. I wanted the user to simply include the header to get access to those functions without having to include some lib or cpp file. Simplicity.
Inline seemed to work, however I forgot to tell I had a few globals too which are still defined multiple times.
-
Get rid of the globals or put em in a cpp file.
gg
-
I solved this by using a class:
a.h:
Code:
#ifndef A_H
#define A_H
class AA
{
void Func()
{
...
}
int Data;
};
#endif