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

Conditionally link a library

P: n/a
Hello,

I use a #define like WITH_MYSTUFF to conditionally compile code within
#ifdef WITH_MYSTUFF. I would now like the same define to conditionally link
with a library. In the linker settings of VS.NET 2003 I have 'Input ->
Additional
Dependencies' where I can add my .lib files the linker should use.

How do I tell the linker (by a macro ?) somthing like this:

'link with mystuff.lib if WITH_MYSTUFF is defined'

Any idea how this could be done?

Many thanks, Felix
Nov 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Felix wrote:
Hello,

I use a #define like WITH_MYSTUFF to conditionally compile code within
#ifdef WITH_MYSTUFF. I would now like the same define to
conditionally link with a library. In the linker settings of VS.NET
2003 I have 'Input -Additional
Dependencies' where I can add my .lib files the linker should use.

How do I tell the linker (by a macro ?) somthing like this:

'link with mystuff.lib if WITH_MYSTUFF is defined'

Any idea how this could be done?
Simple answer: you can't.

More complicated answer: Generally, it's not necessary. If nothing in the
library is referenced (and presumably it's not, otherwise you'd be getting
unresolved external errors from the linker), then the linker won't pull
anything from the library into the linked image. It will make the link take
a little longer (a couple seconds at most, unless the library is extremely
large). You can try adding the /verbose option to your linker command line
options to see what happens to a library that's not referenced.

Most complicated answer: you can use another project system, such as a
hand-written makefile, to do your builds. In such an environment you could
decide which libraries to include in the link based on whatever criteria you
choose.

-cd
Nov 1 '06 #2

P: n/a

"Felix" <fb@ltec.chwrote in message
news:eh**************@TK2MSFTNGP04.phx.gbl...
Hello,

I use a #define like WITH_MYSTUFF to conditionally compile code within
#ifdef WITH_MYSTUFF. I would now like the same define to conditionally
link
with a library. In the linker settings of VS.NET 2003 I have 'Input ->
Additional
Dependencies' where I can add my .lib files the linker should use.

How do I tell the linker (by a macro ?) somthing like this:

'link with mystuff.lib if WITH_MYSTUFF is defined'
#if WITH_MYSTUFF
#pragma comment(lib, "mystuff")
#endif
>
Any idea how this could be done?

Many thanks, Felix


Nov 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.