Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2006

Tip: Looking for answers? Try searching our database.

MSVC not linking in "unused" libraries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Stankevitz - 03 Apr 2006 19:55 GMT
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
Bruno van Dooren - 03 Apr 2006 20:19 GMT
> 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.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Chris Stankevitz - 03 Apr 2006 21:57 GMT
"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 - 04 Apr 2006 08:30 GMT
> "Bruno van Dooren"
> > You should be able to use the linker option /INCLUDE for that.
[quoted text clipped - 9 lines]
>
> 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.

Signature

Kind regards,
   Bruno.
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Chris Stankevitz - 11 Apr 2006 22:27 GMT
> If your libraries are static libraries, then a common technique is to have
> 1
[quoted text clipped - 3 lines]
> 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 - 12 Apr 2006 10:30 GMT
> > If your libraries are static libraries, then a common technique is to have
> > 1
[quoted text clipped - 13 lines]
> 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?

Signature

Kind regards,
   Bruno.
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Chris Stankevitz - 03 Apr 2006 21:52 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.