From: George on
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
From: Cezary H. Noweta on
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
From: George on
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
From: Cezary H. Noweta on
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
From: George on
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
 |  Next  |  Last
Pages: 1 2
Prev: DLL vs static library
Next: CString bug?