I'm in Visual Studio 2003. I have a function in a very common module which requires 3 other modules. I want only projects using the new function to have to include the 3 other modules, and those that don't reference the function to link without "unresolved external symbol" errors. I tried function level linking, OPT:REF and every project setting I could think of, but the linker always complains. I made a simple example for testing. Any ideas would be awesome...
//main.cpp
//#include "a.h"
int _tmain(int argc, _TCHAR* argv[])
{
//a();
return 0;
}
//a.h
#include "b.h"
void a();
//a.cpp
#include "a.h"
#include "b.h"
void a()
{
b();
}
//b.h
void b();
//b.cpp
#include "b.h"
void b()
{
}
I need for the project to compile fine with only main.cpp and a.cpp in the project as long as a() is never called. If a() is called in _tmain(), then of course b.cpp would have to be added to the project.
The linker doesn't seem to apply the OPT:REF until after it is sure EVERY function referenced ANYWHERE is in the project. Even if it (b()) is referenced in an unreferenced function (a()).