experchange > vc.* > vc.language

Angel Tsankov (03-04-06, 06:17 PM)
May I specify a relative or an absolute path in the pragma comment lib directive? If so, how?
Carl Daniel [VC++ MVP] (03-04-06, 07:16 PM)
Angel Tsankov wrote:
> May I specify a relative or an absolute path in the pragma comment
> lib directive? If so, how?


No, just a file name. The linker will search the library paths (specified in
the environment or command line) to find the library.

-cd
David Lowndes (03-04-06, 07:28 PM)
>May I specify a relative or an absolute path in the pragma comment lib directive? If so, how?

The MSDN documentation implies that you can. I've never tried it
myself though:

"
lib
Places a library-search record in the object file. This comment type
must be accompanied by a commentstring parameter containing the name
(and possibly the path) of the library that you want the linker to
search. The library name follows the default library-search records in
the object file; the linker searches for this library just as if you
had named it on the command line provided that the library is not
specified with /nodefaultlib. You can place multiple library-search
records in the same source file; each record appears in the object
file in the same order in which it is encountered in the source file.

If the order of the default library and an added library is important,
compiling with the /Zl switch will prevent the default library name
from being placed in the object module. A second comment pragma then
can be used to insert the name of the default library after the added
library. The libraries listed with these pragmas will appear in the
object module in the same order they are found in the source code.
"

Dave
Angel Tsankov (03-04-06, 10:01 PM)
> The MSDN documentation implies that you can.

Yes, it does not say that it is impossible and that's why I asked how it is done.
David Lowndes (03-05-06, 01:49 AM)
>Yes, it does not say that it is impossible and that's why I asked how it is done.

What have you tried, and what's been the result?

I've just tried this:

#pragma comment( lib, "c:\\rubbish\\user32.lib" )

and got this:

fatal error LNK1104: cannot open file 'c:\rubbish\user32.lib'

So it clearly does what it says to some degree!

Dave
Angel Tsankov (03-05-06, 03:32 AM)
> >Yes, it does not say that it is impossible and that's why I asked how it is done.
> What have you tried, and what's been the result?
> I've just tried this:
> #pragma comment( lib, "c:\\rubbish\\user32.lib" )
> and got this:
> fatal error LNK1104: cannot open file 'c:\rubbish\user32.lib'
> So it clearly does what it says to some degree!


I tried with a relative path like this:

#pragma comment( lib, "dir/file.lib" )

and got the same error.
David Lowndes (03-05-06, 12:21 PM)
>I tried with a relative path like this:
>#pragma comment( lib, "dir/file.lib" )
>and got the same error.


Right... so, where is file.lib in relation to other things?

What are you expecting it to do...?

Try a fixed path to exactly where your lib is and see if that works,
this does for me.

#pragma comment( lib, "C:\\Program Files\\Microsoft Visual Studio
8\\VC\\PlatformSDK\\Lib\\user32.lib" )

Dave
Angel Tsankov (03-05-06, 04:22 PM)
> >I tried with a relative path like this:
> Right... so, where is file.lib in relation to other things?
> What are you expecting it to do...?
> Try a fixed path to exactly where your lib is and see if that works,
> this does for me.
> #pragma comment( lib, "C:\Program Files\Microsoft Visual Studio
> 8\VC\PlatformSDK\Lib\user32.lib" )


Yes, a fixed (absolute) path works for me, too.
Relative paths, however, do not work. I tried the following:

#pragma comment( lib, "/dir/file.lib" )
#pragma comment( lib, "\\dir\\file.lib" )
#pragma comment( lib, ".\\dir\\file.lib" )

in combination Library files in the IDE containg any of these paths:
d:\libraries\library_files
d:\libraries\library_files\
d:/libraries/library_files
d:/libraries/library_files/

The full path to the .lib file is
d:\libraries\library_files\dir\file.lib

Having tried all this, I tend to assume that it is not possible to specify a relative (i.e. an incomplete path) in a pragma comment
lib directive.
David Lowndes (03-05-06, 05:10 PM)
>Yes, a fixed (absolute) path works for me, too.
>Relative paths, however, do not work. I tried the following:
>...
>Having tried all this, I tend to assume that it is not possible to specify a relative (i.e. an incomplete path) in a pragma comment
>lib directive.


As the documentation makes no specific reference to relative paths,
I'd have to conclude from the results you show that it's not catered
for.

Dave
James Park (03-05-06, 06:01 PM)
"Angel Tsankov" <fn42551> wrote in message
news:6298
[..]
> d:\libraries\library_files\dir\file.lib
> Having tried all this, I tend to assume that it is not possible to specify
> a relative (i.e. an incomplete path) in a pragma comment lib directive.


I have no problems specifying paths relative to the source file.
David Lowndes (03-06-06, 02:06 AM)
>> Having tried all this, I tend to assume that it is not possible to specify
>> a relative (i.e. an incomplete path) in a pragma comment lib directive.

>I have no problems specifying paths relative to the source file.


Perhaps you can give us an example that works for you James?

Dave
James Park (03-06-06, 04:07 AM)
"David Lowndes" <DavidL> wrote in message
news:f45v
>>> Having tried all this, I tend to assume that it is not possible to
>>> specify
>>> a relative (i.e. an incomplete path) in a pragma comment lib directive.

>>I have no problems specifying paths relative to the source file.

> Perhaps you can give us an example that works for you James?


No problemo:

#include <windows.h>
#include <tchar.h>

#pragma comment( lib, "..\\..\\..\\..\\..\\..\\..\\Program Files\\Microsoft
Visual Studio 8\\VC\\PlatformSDK\\Lib\\user32.lib" )

int _tmain(int argc, _TCHAR* argv[])
{
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
FindWindow(NULL, NULL);
}
Carl Daniel [VC++ MVP] (03-06-06, 07:51 AM)
James Park wrote:
> "David Lowndes" <DavidL> wrote in message
> news:f45v
> No problemo:
> #include <windows.h>
> #include <tchar.h>
> #pragma comment( lib, "..\..\..\..\..\..\..\Program
> Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib\user32.lib" )


.... which would have worked even if the linker ignored the path completely.
Have you tried a .lib that's in a directory that's not on the lib path? (I
haven't).

-cd
James Park (03-06-06, 08:22 AM)
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam>
wrote in message news:a164
> James Park wrote:
> ... which would have worked even if the linker ignored the path
> completely. Have you tried a .lib that's in a directory that's not on the
> lib path? (I haven't).


I've tried using a bad path (removed one "..\\") and that didn't build. I've
also tried copying user32.lib to the directory one level above and using
"..\\user32.lib" and that built fine too.
Carl Daniel [VC++ MVP] (03-06-06, 09:19 AM)
James Park wrote:
> "Carl Daniel [VC++ MVP]"
> I've tried using a bad path (removed one "..\") and that didn't
> build. I've also tried copying user32.lib to the directory one level
> above and using "..\user32.lib" and that built fine too.


Sounds like it works then :)

In your test, was the .obj file in the same directory as the source file?
It would seem odd that a path relative to the source file would be
meaningful to the linker...

-cd

Similar Threads