Visual C++ link optimization to keep functions/data that are in a particular .obj file

Viewed 163

I have a static library which contains a bunch of functions with an identical interface.

CBase* instantiateCImplA(args);
CBase* instantiateCImplB(args);
CBase* instantiateCImplC(args);

Each of these functions will be located across different .obj files, and a global list of pointers to each of these functions is maintained in another .obj file:

map<string, InstantiatorCImplFunc > g_InstantiatorCImplList;

There is also a function that that calls one of these functions based on a argument provided

CBase* instantiateCImple(string whichCImpl, args)
{
  assert( g_CImplInstantiatorList[whichCImpl] != g_CImplInstantiatorList.end() );
  return g_CImplInstantiatorList[whichCImpl](args);
}

The idea is that an application that links to this library will only be instantiating a CImpl class by specifying exactly what implementation it needs through the instantiateCImple() function. Therefore, which implementation the application will use is determined at run-time, and thus cannot be predicted at link-time.

What I need to do is explicitly force the librarian to have symbol reference to these functions. I only know two ways to do this. One way is to simply force all symbols across the whole library, (/OPT:NOREF), the other way is I can specify particular symbols I want to keep (/INCLUDE:symbol). Although the latter will still allow me to maintain an optimal image size it is rather inconvenient to have to specify each symbol that I'll need (in my situation this would need to be function references and global variable references)

Is there any similar link optimization option that allows you to force the librarian to keep all the symbol references in a particular .obj file? instead of by symbol?

0 Answers
Related