Click to See Complete Forum and Search --> : #pragma comment


Salvadoravi
March 4th, 2008, 06:16 PM
Hi all,

I am using the following code line:


#pragma comment(lib, "wininet.lib")


Is there a way to print a message to the user if the file not found??

For example: If I rename wininet.lib to something else, I get a Linker error when compiling the code.
Ideally I would the user to get a message like: "wininet.lib not found try reinstalling the program"
How can I do it??

Many thanks!!!

wildfrog
March 4th, 2008, 06:58 PM
To my knowledge there aren't any pragmas or precompiler constructs that can check for missing files.

Maybe you can solve your problem with a buildscript and the FindUnderPath (http://msdn2.microsoft.com/en-us/library/ms164293(VS.80).aspx) task.

- petter

lmoreault
March 5th, 2008, 08:30 AM
If you mean at runtime, there will be no such thing.

Lib will be statically linked to your .exe file

What you should deal with is more when linking DLL (with LoadLibrary() for example)

Salvadoravi
March 6th, 2008, 04:26 AM
Thank you guys.

Yes Runtime.
If I understand it correctly than when I compile my program ,
The EXE created already contain the LIB file???
So when I publish my program I don't need to add the lib file to the pakage installer, only the dll.
Is that right?


Thanks again

GNiewerth
March 6th, 2008, 04:57 AM
Thank you guys.

Yes Runtime.
If I understand it correctly than when I compile my program ,
The EXE created already contain the LIB file???
So when I publish my program I don't need to add the lib file to the pakage installer, only the dll.
Is that right?


Thanks again

Depends whether you link the library statically or dynamically. When linking statically all executable code is taken from the library and copied into your application code (you donīt need additional DLLs, but it makes your application bigger).
When linking dynamically your application loads a DLL when needed and calls code from that library, but you need that DLL on every system to run your application.

Salvadoravi
March 6th, 2008, 07:08 AM
Thank you,

I am still a little bit confused about the *.lib file.
Is it needed on the client computer to run the program?
Or is it just needed by the compiler to create the exe??

Many thanks!

GNiewerth
March 6th, 2008, 07:16 AM
.lib files are never used by an executable (except for linkers ;)). You wonīt have to package it with your executable, just make sure you either link statically or provide the DLL your application is linked against.

Mybowlcut
March 6th, 2008, 07:20 AM
I think that it's the DLL file that is needed, not the .lib file... I could be wrong. :s

Edit: Woohoo I was right... one question, how do find out if you are statically or dynamically linking to a library? For example.. I use SDL but I am unsure if I am statically linking to it or not? I ask because when I debug my program which uses the SDL library, there are HEAPS of lines saying this during the period that images are being loaded and it slows down my program:
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\zlib1.dll', No symbols loaded.
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\libpng12.dll'
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\zlib1.dll'
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\libpng12.dll', No symbols loaded.
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\zlib1.dll', No symbols loaded.
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\libpng12.dll'I'm presuming this is dynamic linking? I'd prefer to link statically because it's just too slow...

Sorry about the semi-thread-hi-jack. :wave:

Salvadoravi
March 6th, 2008, 07:27 AM
.lib files are never used by an executable (except for linkers ;)). You wonīt have to package it with your executable, just make sure you either link statically or provide the DLL your application is linked against.

Excellent, Thank you GNiewerth!

GNiewerth
March 6th, 2008, 07:55 AM
I think that it's the DLL file that is needed, not the .lib file... I could be wrong. :s

Edit: Woohoo I was right... one question, how do find out if you are statically or dynamically linking to a library? For example.. I use SDL but I am unsure if I am statically linking to it or not? I ask because when I debug my program which uses the SDL library, there are HEAPS of lines saying this during the period that images are being loaded and it slows down my program:
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\zlib1.dll', No symbols loaded.
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\libpng12.dll'
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\zlib1.dll'
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\libpng12.dll', No symbols loaded.
'Checkers_SDL.exe': Loaded 'C:\WINDOWS\system32\zlib1.dll', No symbols loaded.
'Checkers_SDL.exe': Unloaded 'C:\WINDOWS\system32\libpng12.dll'I'm presuming this is dynamic linking? I'd prefer to link statically because it's just too slow...

Sorry about the semi-thread-hi-jack. :wave:

This happens only in debug builds, I think. For the release build there should be no significant speed difference between dynamic and static linking.

There are tools like PeBrowsePro and DependencyWalker that inspect executables/DLLs and displays their import section/dependencies.

Mybowlcut
March 6th, 2008, 08:43 AM
This happens only in debug builds, I think. For the release build there should be no significant speed difference between dynamic and static linking.

There are tools like PeBrowsePro and DependencyWalker that inspect executables/DLLs and displays their import section/dependencies.Yeah but that's just it, the wait for it just to get past this part takes atleast 10 seconds each time. :( Why would I need to search for import section/dependencies?

GNiewerth
March 6th, 2008, 09:00 AM
To check which DLLs are loaded at startup.