Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 3.2 KB

dot-lib-files-as-linker-input.md

File metadata and controls

65 lines (52 loc) · 3.2 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
.Lib Files as Linker Input | Microsoft Docs
11/04/2016
cpp-tools
article
VC.Project.VCLinkerTool.AdditionalDependencies
C++
OMF libraries
linking [C++], OMF libraries
import libraries, linker files
libraries [C++], .lib files as linker input
COFF files, import libraries
default libraries [C++], linker output
default libraries [C++]
defaults [C++], libraries
.lib files
dc5d2b1c-2487-41fa-aa71-ad1e0647958b
15
corob-msft
corob
ghogen

.Lib Files as Linker Input

LINK accepts COFF standard libraries and COFF import libraries, both of which usually have the extension .lib. Standard libraries contain objects and are created by the LIB tool. Import libraries contain information about exports in other programs and are created either by LINK when it builds a program that contains exports or by the LIB tool. For information on using LIB to create standard or import libraries, see LIB Reference. For details on using LINK to create an import library, see the /DLL option.

A library is specified to LINK as either a file name argument or a default library. LINK resolves external references by searching first in libraries specified on the command line, then in default libraries specified with the /DEFAULTLIB option, and then in default libraries named in .obj files. If a path is specified with the library name, LINK looks for the library in that directory. If no path is specified, LINK looks first in the directory that LINK is running from, and then in any directories specified in the LIB environment variable.

To add .lib files as linker input in the development environment

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.

  2. Choose the Input property page in the Linker folder.

  3. Modify the Additional Dependencies property to add the .lib files.

To programmatically add .lib files as linker input

Example

The following sample shows how to build and use a .lib file. First, build a .lib file:

// lib_link_input_1.cpp  
// compile by using: cl /LD lib_link_input_1.cpp  
__declspec(dllexport) int Test() {  
   return 213;  
}  

And then, compile this sample by using the .lib file you just created:

// lib_link_input_2.cpp  
// compile by using: cl /EHsc lib_link_input_1.lib lib_link_input_2.cpp   
__declspec(dllimport) int Test();  
#include <iostream>  
int main() {  
   std::cout << Test() << std::endl;  
}  
213  

See Also

LINK Input Files
Linker Options