Programming/C+±
cpp-lib-and-dll-on-visual-studio (1/2)
BaeMinCheon
2019. 2. 23. 20:41
cpp-lib-and-dll-on-visual-studio (1/2)
- this post covers
- what LIB and DLL files are
- how to make LIB files
- how to use LIB files
- next post covers
- how to make DLL files
- how to use DLL files
- difference between LIB and DLL
- environment
- Windows 10 / Home
- Visual Studio 2017 / Community
overview
- recap on c/cpp compilation
- when you compile a c/cpp code, the process above will be done
- we call the time during the process; compile-time
- and the time after the execution; run-time
- LIB file
- its file extension is
.lib
- ex)
cudart.lib
in CUDA 9.0 version
- ex)
- it is called static-link-LIBrary
- for the reason that linking on compile-time
- it is used for ease of execution
- by using LIB file, you only need to handle execution file
- its file extension is
- DLL file
- its file extension is
.dll
- ex)
cudart32_90.dll
in CUDA 9.0 version
- ex)
- it is called Dynamic-Link-Library
- for the reason that linking on run-time
- it is used for saving memory usage
- both main-memory(RAM) and auxiliary-memory(HDD or SSD)
- its file extension is
make-lib
- open Visual Studio and make an empty solution
- add a new project by selecting
Windows Desktop Wizard
- select
Static Library (.lib)
inApplication type:
combo box - uncheck
Precompiled Header
radio button
- make a header file and fill with the code above
- make a source file and fill with the code above
- build solution and check the generated LIB file in output directory
use-lib
- open or make any project easy to include the library
- I recommend you to make
Empty Project
for convenience
- prepare any c/cpp file in the project
- you should add the LIB project path into
Addtional Include Directories
in project property window- the path will be used for including header file
- in my case, the path is
D:\Code\VS2017\practice-lib\MathFuncsLib
- now you can include the header file
- you should add the LIB output path into
Additional Library Directories
in project property window- the path will be used for setting range of including LIB file
- in my case, the path is
D:\Code\VS2017\practice-lib\Debug
- you should add the LIB file name into
Additional Dependencies
in project property window- the name will be used for including certain LIB file
- in my case, the name is
MathFuncsLib.lib
- write the code above and check out the output
- now you have used LIB file !
to-be-continued...
- next post will cover the rest of this topic
- make-dll
- use-dll
- comparison