#pragma comment
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: #pragma comment

  1. #1
    Join Date
    Dec 2005
    Posts
    445

    #pragma comment

    Hi all,

    I am using the following code line:

    Code:
    #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!!!

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: #pragma comment

    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 task.

    - petter

  3. #3
    Join Date
    Feb 2008
    Posts
    47

    Re: #pragma comment

    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)
    Visual Studio 2005 Professional

  4. #4
    Join Date
    Dec 2005
    Posts
    445

    Re: #pragma comment

    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
    Last edited by Salvadoravi; March 6th, 2008 at 04:29 AM.

  5. #5
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: #pragma comment

    Quote Originally Posted by Salvadoravi
    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.

  6. #6
    Join Date
    Dec 2005
    Posts
    445

    Re: #pragma comment

    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!

  7. #7
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: #pragma comment

    .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.

  8. #8
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: #pragma comment

    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:
    Code:
    '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.
    Last edited by Mybowlcut; March 6th, 2008 at 07:25 AM.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  9. #9
    Join Date
    Dec 2005
    Posts
    445

    Re: #pragma comment

    Quote Originally Posted by GNiewerth
    .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!

  10. #10
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: #pragma comment

    Quote Originally Posted by Mybowlcut
    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:
    Code:
    '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.
    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.

  11. #11
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: #pragma comment

    Quote Originally Posted by GNiewerth
    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?
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  12. #12
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center