Search code examples
c++clinkerlinkage

an in-code keyword for linking a .lib file


I'm using VS2010 to write some win32 app. I normally add .lib files to linkage using to project property manager. yet, sometimes, when I just want to test an API function , I don't want to modify my project file , but rather just add a removable line for linking with the required lib

What is the linker keyword for linking with a given .lib file?


Solution

  • You can use #pragma comment command

    Example:

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

    Another example:

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

    Just put in hmm.. before int main(){}

    http://support.microsoft.com/kb/153901

    http://msdn.microsoft.com/en-us/library/7f0aews7%28v=vs.71%29.aspx

    If there are problems:

    Ignore #pragma comment(lib, ...)?

    Unresolved external symbol when linking my library