MSVC not linking in "unused" libraries

  • Thread starter Thread starter Chris Stankevitz
  • Start date Start date
C

Chris Stankevitz

At link time, MSVC determines some of my libraries are unused and doesn't
link them into my exe. This undesirable feature causes problems when I
employ the factory pattern. With the factory pattern, the app decides at
run time which code to use.

Is there a link option to turn of this feature?

MSVC 7.1 .net 2003 69462-270-0000007-18536

Thanks,

Chris
 
At link time, MSVC determines some of my libraries are unused and doesn't
link them into my exe. This undesirable feature causes problems when I
employ the factory pattern. With the factory pattern, the app decides at
run time which code to use.

You should be able to use the linker option /INCLUDE for that.
Alternatively, you can use LoadLibrary at runtime to load dlls at runtime.
That way you have an extensible plugin framework.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
At link time, MSVC determines some of my libraries are unused and doesn't
link them into my exe. This undesirable feature causes problems when I
employ the factory pattern. With the factory pattern, the app decides at
run time which code to use.

Is there a link option to turn of this feature?

I'm going to try /OPT:NOREF
 
"Bruno van Dooren"
You should be able to use the linker option /INCLUDE for that.
Alternatively, you can use LoadLibrary at runtime to load dlls at runtime.
That way you have an extensible plugin framework.


Hi Bruno,

Thanks for the help. Do I have to use /INCLUDE for every symbol? My
developers are adding objects (symbols) via the Factory pattern every day.
I don't want to change my link options everytime I add an object. My app is
about 1 million lines of code.

I will try the /OPT:NOREF option.

Thanks,

Chris
 
"Bruno van Dooren"
Hi Bruno,

Thanks for the help. Do I have to use /INCLUDE for every symbol? My
developers are adding objects (symbols) via the Factory pattern every day.
I don't want to change my link options everytime I add an object. My app is
about 1 million lines of code.

I will try the /OPT:NOREF option.

If your libraries are dlls, then you have to reference only 1 symbol per
library.

If your libraries are static libraries, then a common technique is to have 1
function that is never to be called by actual code, put a call to all other
functions in there, and then use /INCLUDE to reference that unused function
that automatically references all other functions.

/OPT:NOREF is the default for debug builds, so if your debug configuration
does not include all the libraries, you know it won't work.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
Bruno van Dooren said:
If your libraries are static libraries, then a common technique is to have
1
function that is never to be called by actual code, put a call to all
other
functions in there, and then use /INCLUDE to reference that unused
function
that automatically references all other functions.

Bruno,

Thanks for your help.

I'm curious about this trick. What do you mean by "put a call to all other
functions"? Are you assuming that my static library consists of only global
functions? My static libraries consist of many classes each with many
functions, a few static functions, and some static variables. What would my
"dummy function" look like for such a static library?

Thanks,

Chris
 
Bruno van Dooren said:
Bruno,

Thanks for your help.

I'm curious about this trick. What do you mean by "put a call to all other
functions"? Are you assuming that my static library consists of only global
functions? My static libraries consist of many classes each with many
functions, a few static functions, and some static variables. What would my
"dummy function" look like for such a static library?

The way I saw this technique used after some googling (though i cannot find
that page again it seems. I hate it when that happens) looked like this:

void dummyFunctionForSymbolReference(void)
{
Class1 myClass1();
Class2 myClass3();
Class3 myClass3();
}

You only need to reference each class once inside the function that you
include by force. all the classes that are contained inside that function
should be added to the library.

You can easily test this with one of your classes that contain both member
and static function sand variables.

This page:
http://austria.sourceforge.net/dox/html/group__GenericFactories.html
seems to describe another trick for making sure that symbols get included.
Maybe that could be usefull to you as well?

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
Back
Top