I'm trying to architect a program to eliminate unresolved symbols. I'm
doing so in the following manner:
// Header file
class Interface {
public:
static void myFunc();
// End Header fileQuote:};
// Library 1
Interface::myFunc() {assert (0);}
if (a) { // 'a' would *ONLY* be set in a program that also linked library
2.
Interface::myFunc();
else {Quote:}
otherFunc();
// End Library 1Quote:}
// Library 2
Interface::myFunc() { /* real code */ }
// End Library 2
As you can see, myFunc should *NEVER* be called from a program that just
uses library 1. That is correct operation.
However, in some programs, I want to set 'a' and call the myFunc() in
library 2. Obviously I can't remove the myFunc() dummy declaration from
library 1 or I will get an unresolved symbol problem when linking programs
that only use library 1.
But, I'm afraid that the linker may arbitrarily choose one of the myFunc()'s
and sometimes choose the wrong one. Is every linker's choice deterministic?
I mean, can I always link library 2 before library 1 and guarantee that the
second myFunc() is chosen when it is linked? Is there some other linker or
compiler switch I can give to be sure that the library 2 implementation is
used when it is linked? Or, is making a program like the above guaranteed
to cause cross-platform havoc?
Thanks in advance,
Scott