Hello everyone,


Just want to confirm whether my understanding is correct.

The statement in source file,

[Code]
#pragma comment(lib, "DLL1.lib")
[/Code]

has the same effect (as an alternative approach) of set DLL1.lib as implicit
link library input in project link settings? So, we choose either one method
to configure implicit linking input library?


thanks in advance,
George

Re: #pragma comment lib by Cezary

Cezary
Sun Apr 13 02:48:14 CDT 2008

Hello,

> The statement in source file,
>
> [Code] #pragma comment(lib, "DLL1.lib") [/Code]
>
> has the same effect (as an alternative approach) of set DLL1.lib as
> implicit link library input in project link settings? So, we choose
> either one method to configure implicit linking input library?

Yes, but notice that the library will always be linked unless you will
use /NODEFAULTLIB[:lib] linker option. It is important when you have two
conflicting versions of the same (static) library. Mainly they will be
release and debug versions. In such case you should use:

#ifdef DEBUG
#pragma comment(lib, "MYLIBd")
#else /* #ifdef DEBUG */
#pragma comment(lib, "MYLIB")
#endif /* #ifdef DEBUG */

Otherwise you will have to use ,,/NODEFAULTLIB:MYLIB MYLIBd.lib'' when
linking debug version of your app. This causes some overtyping then
using lib names in command line explicitly.

This problem does not concern dynamic libraries when they are one
version DLLs.

-- best regards

Cezary Noweta

Re: #pragma comment lib by George

George
Sun Apr 13 03:37:01 CDT 2008

Thanks Cezary,


1.

> It is important when you have two
> conflicting versions of the same (static) library.

Good to learn #pragma comment lib can work not only for implicit link import
lib, but also static lib.

2.

> Otherwise you will have to use ,,/NODEFAULTLIB:MYLIB MYLIBd.lib'' when
> linking debug version of your app. This causes some overtyping then
> using lib names in command line explicitly.

Why do you need to explicit remove MYLIB link when build a debug version?
Confused. In your code, if you use macro DEBUG in debug version compile, the
code,

#pragma comment(lib, "MYLIB")

will not be seen, and there should not be any conflict? Could you clarify
please?


regards,
George

Re: #pragma comment lib by Cezary

Cezary
Sun Apr 13 04:20:07 CDT 2008

Hello,

>> Otherwise you will have to use ,,/NODEFAULTLIB:MYLIB MYLIBd.lib''
>> when linking debug version of your app. This causes some overtyping
>> then using lib names in command line explicitly.
>
> Why do you need to explicit remove MYLIB link when build a debug
> version? Confused. In your code, if you use macro DEBUG in debug
> version compile, the code,
>
> #pragma comment(lib, "MYLIB")
>
> will not be seen, and there should not be any conflict? Could you
> clarify please?

I wrote ,,otherwise''. I meant single ,,#pragma comment(lib, ...)''
(your example) as opposite to my conditional ,,#ifdef'' example.

1. ,,otherwise'' situation

#pragma comment(lib, "MYLIB") /* you should remove */
/* MYLIB by /NODEFAULTLIB */
/* linker option */
/* if you want link with */
/* debug version (MYLIBd) */

2. my example

#ifdef DEBUG
#pragma comment(lib, "MYLIBd")
#else /* #ifdef DEBUG */
#pragma comment(lib, "MYLIB")
#endif /* #ifdef DEBUG */

Here, if you want to use debug version (MYLIBd) you will not need to
remove explicitly (this is what you wrote above).

-- best regards

Cezary Noweta

Re: #pragma comment lib by George

George
Sun Apr 13 09:15:00 CDT 2008

Thanks Cezary,


I am interested in what are the default libs for linker, as the name of
NODEFAULTLIB indicates. :-)

Besides the ones in #pragma comment lib, are there any other libs treated as
default lib? Such as some SDK default lib? Where can I find a list?


regards,
George

Re: #pragma comment lib by Igor

Igor
Sun Apr 13 09:25:20 CDT 2008

"George" <George@discussions.microsoft.com> wrote in message
news:FBF32944-99EC-4521-A9C5-AA6DC522877B@microsoft.com
> I am interested in what are the default libs for linker, as the name
> of NODEFAULTLIB indicates. :-)

Those that are mentioned in the source code with #pragma comment(lib).

> Besides the ones in #pragma comment lib, are there any other libs
> treated as default lib? Such as some SDK default lib?

There's nothing magical about Platform SDK libraries. They get linked
into your executable because you either a) specify them on the command
line (or in project settings), or b) put #pragma comment in your code
(or perhaps include a header that does that).
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: #pragma comment lib by George

George
Sun Apr 13 22:54:00 CDT 2008

Sorry, Igor.


> There's nothing magical about Platform SDK libraries. They get linked
> into your executable because you either a) specify them on the command
> line (or in project settings), or b) put #pragma comment in your code
> (or perhaps include a header that does that).

It is my mis-understanding before that I think besides the libs specified in
linker input option and #pragma comment lib, there is some default SDK libs
which will be injected by linker implicitly (so, you can not remove them).

Now I understand there is nothing special about SDK libs. :-)


regards,
George