By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

MSVC not linking in "unused" libraries

P: n/a
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
Apr 3 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
> 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
br**********************@hotmail.com
Remove only "_nos_pam"
Apr 3 '06 #2

P: n/a

"Chris Stankevitz" wrote
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
Apr 3 '06 #3

P: n/a

"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
Apr 3 '06 #4

P: n/a
> "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.


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.
br**********************@hotmail.com
Remove only "_nos_pam"
Apr 4 '06 #5

P: n/a

"Bruno van Dooren" <br**********************@hotmail.com> wrote
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
Apr 11 '06 #6

P: n/a
> "Bruno van Dooren" <br**********************@hotmail.com> wrote
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?


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/h...Factories.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.
br**********************@hotmail.com
Remove only "_nos_pam"

Apr 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.