Skip to content

Commit f3add12

Browse files
committed
dynamic linking
1 parent d31d9b5 commit f3add12

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

HelloWorld/HelloWorld/HelloWorld.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<Link>
8080
<GenerateDebugInformation>true</GenerateDebugInformation>
8181
<AdditionalLibraryDirectories>$(SolutionDir)Dependencies\GLFW\lib-vc2015</AdditionalLibraryDirectories>
82-
<AdditionalDependencies>glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
82+
<AdditionalDependencies>glfw3dll.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
8383
</Link>
8484
</ItemDefinitionGroup>
8585
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -106,7 +106,7 @@
106106
<EnableCOMDATFolding>true</EnableCOMDATFolding>
107107
<OptimizeReferences>true</OptimizeReferences>
108108
<AdditionalLibraryDirectories>$(SolutionDir)Dependencies\GLFW\lib-vc2015</AdditionalLibraryDirectories>
109-
<AdditionalDependencies>glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
109+
<AdditionalDependencies>glfw3dll.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
110110
</Link>
111111
</ItemDefinitionGroup>
112112
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

HelloWorld/HelloWorld/Main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// glfw3dll.lib is actually kind of the static library that we use with the dll. This file actually contains all of the locations of the functions and symbols inside glfw3.dll so that we can link against them at compile time
66
// glfw3.lib is the static library, we do not need glfw3.dll file to be without exe file at runtime
77

8+
// you should put your dll file into the same folder as your executable
89
#include<iostream>
910
#include <GLFW/glfw3.h>
1011

README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [NewProject](#newproject)
55
- [Youtube](#youtube)
66
- [Date: 2018-12-28](#2018-12-28)
7+
- [dynamic linking](#dynamic-linking)
78
- [Date: 2018-12-27](#2018-12-27)
89
- [static linking](#static-linking)
910
- [Date: 2018-12-26](#2018-12-26)
@@ -109,7 +110,7 @@ It provides a recommended `VS` *Directory Structure* as follows:
109110
- [x] "Dynamic Arrays in C++ (std::vector)"
110111
- [x] "Optimizing the usage of std::vector in C++"
111112
- [x] "Using Libraries in C++ (Static Linking)"
112-
- [ ] "Using Dynamic Libraries in C++"
113+
- [x] "Using Dynamic Libraries in C++"
113114
- [ ] "Making and Working with Libraries in C++ (Multiple Projects in Visual Studio)"
114115
- [ ] "How to Deal with Multiple Return Values in C++"
115116
- [ ] "Templates in C++"
@@ -145,13 +146,36 @@ It provides a recommended `VS` *Directory Structure* as follows:
145146
>
146147
> A more complete description is available in the GCC [documentation on search paths](https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html).
147148
149+
#### dynamic linking
150+
In my opinion, **dynamic linking** means your executable is separated from some **.dll** (dynamic linking libraries). On the contrary, **static linking** means when you compile and link your code, some necessary libraries are incorporated into your final executable file, so it doesn't need some extra libraries support since it already includes all necessary stuffs. In other word, because static linking relates with some compilation and linking procedure, it actually has to consider some optimizations so that the final executable will be more efficient.
151+
* Dynamic linking vs Static linking [link](http://cs-fundamentals.com/tech-interview/c/difference-between-static-and-dynamic-linking.php)
152+
> The program we write might make use of other programs (which is usually the case), or libraries of programs. These other programs or libraries must be brought together with the program we write in order to execute it.
153+
>
154+
> Linking is the process of bringing external programs together required by the one we write for its successful execution. Static and dynamic linking are two processes of collecting and combining multiple object files in order to create a single executable. Here we will discuss the difference between them. Read full article on static and dynamic linking for more details.
155+
>
156+
> Linking can be performed at both compile time, when the source code is translated into machine code; and load time, when the program is loaded into memory by the loader, and even at run time, by application programs. And, it is performed by programs called linkers. Linkers are also called link editors. Linking is performed as the last step in compiling a program.
157+
>
158+
> After linking, for execution the combined program must be moved into memory. In doing so, there must be addresses assigned to the data and instructions for execution purposes. The above process can be summarized as program life cycle (**write -> compile -> link -> load -> execute**).
159+
160+
161+
162+
| Static Linking | Dynamic Linking |
163+
| ------------------------------------------------------------ | ------------------------------------------------------------ |
164+
| Static linking is the process of copying all library modules used in the program into the final executable image. This is performed by the linker and it is done as the last step of the compilation process. The linker combines library routines with the program code in order to resolve external references, and to generate an executable image suitable for loading into memory. When the program is loaded, the operating system places into memory a single file that contains the executable code and data. This statically linked file includes both the calling program and the called program. | In dynamic linking the names of the external libraries (shared libraries) are placed in the final executable file while the actual linking takes place at run time when both executable file and libraries are placed in the memory. Dynamic linking lets several programs use a single copy of an executable module. |
165+
| Static linking is performed by programs called linkers as the last step in compiling a program. Linkers are also called link editors. | Dynamic linking is performed at run time by the operating system. |
166+
| Statically linked files are significantly larger in size because external programs are built into the executable files. | In dynamic linking only one copy of shared library is kept in memory. This significantly reduces the size of executable programs, thereby saving memory and disk space. |
167+
| In static linking if any of the external programs has changed then they have to be recompiled and re-linked again else the changes won't reflect in existing executable file. | In dynamic linking this is not the case and individual shared modules can be updated and recompiled. This is one of the greatest advantages dynamic linking offers. |
168+
| Statically linked program takes constant load time every time it is loaded into the memory for execution. | In dynamic linking load time might be reduced if the shared library code is already present in memory. |
169+
| Programs that use statically-linked libraries are usually faster than those that use shared libraries. | Programs that use shared libraries are usually slower than those that use statically-linked libraries. |
170+
| In statically-linked programs, all code is contained in a single executable module. Therefore, they never run into compatibility issues. | Dynamically linked programs are dependent on having a compatible library. If a library is changed (for example, a new compiler release may change a library), applications might have to be reworked to be made compatible with the new version of the library. If a library is removed from the system, programs using that library will no longer work. |
171+
148172
***
149173
### 2018-12-27
150174
#### static linking
151175

152176
1. Download **GLFW** [here](https://www.glfw.org/download.html) , choose *32-bit Windows binaries*.
153177
2. Unzip **glfw-3.2.1.bin.WIN32.zip** file
154-
3. Copy **inlucde** and **lib-vc2015** two folders to a new foldercalled **GLFW**
178+
3. Copy **include** and **lib-vc2015** two folders to a new folder called **GLFW**
155179
4. Copy the entire folder **GLFW** to a new folder called **Dependencies**
156180
5. Copy the **Dependencies** folder to project root directory
157181
6. So, the final project folder looks like this:

0 commit comments

Comments
 (0)