You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Content providing information in relation to linking " dlls " in visual studio and different methods provided with advantages and cons..
With a working exampple as well..
This guide demonstrates how to include DLL files in a folder and seamlessly integrate them into the Debug or Build folder to generate a working build directory. It is particularly useful when dealing with libraries that require specific DLL files.
15
15
16
-
#### What is a DLL?
16
+
The following is based on an (IDE) [Visual Studio 2022](https://visualstudio.microsoft.com/vs/)
17
17
18
-
- Dynamic Link Library, alternatively referred to as a (DLL), is an amalgamation of code and its associated data intended for widespread use across diverse applications, employing shared code for streamlined functionality. DLLs are specifically crafted to optimize software performance, enhance efficiency, and promote the systematic reuse of code within application development. As linking is established during runtime or while the program is in active execution.
19
18
19
+
### List of options:
20
20
21
-
#### What can be considered as linking?
21
+
<br>
22
22
23
-
- Linking in programming refers to the process of combining pieces of code or files to create a single executable program. There are two different types of linking in programming that are typically used see the following:
- The linking process happens dynamically, allowing the program to access functions and resources from shared libraries on-the-fly.
32
+
> Example.dll
33
+
> main.cpp
34
+
> Application.sln
35
+
> Application.vcxproj
36
+
> Application.vcxproj.user
37
+
> Application.vcxproj.filters
34
38
35
-
- During runtime linking, the executable (.exe) file is connected with external libraries when the program is being launched or when it is running.
36
39
37
-
Advantages:
40
+
**Advantages:**
38
41
39
-
- Reduced memory usage (Allows the program to share a single copy of a library in the memory, reducing the usage of memory and calls).
42
+
- Linking is done for the user by the (IDE).
43
+
- Beneficial for small projects, where file management is not required.
44
+
- The user does not have to worry about the (IDE) locating them, as long as they are listed within the root directory of the project.
40
45
41
-
- Promotes modularity and reusability (Organizes the code-space reducing the quantity of files required).
46
+
**Cons:**
42
47
43
-
- Ease of maintaining (Librares can be applied or updated without having to re-compile the program).
48
+
- Directory gets cluttered and harder to manage as the project grows in size.
49
+
- Clutteres resource and collaboration effectivness.
44
50
45
-
Cons:
51
+
<br>
46
52
47
-
- Dependency (When libraries are not present or incompatible with the executable or other dependable files, the program may fail to execute or produce a run-time error).
53
+
2.### **Working Directory Linking:**
48
54
49
-
- Security (May include malicious and compromised libraries, that could be overlooked when vertifiying the integrity and authenticity of the loaded libraries).
55
+
Changing the working directory (Location of where the application starts the process of the build and runtime).
50
56
51
-
- Reduced control during compile-time (Addressing error or issues caused by linking can be time consuming as it requires runtime to load them, which makes it harder to catch and fix the issues during development and testing).
52
-
53
-
### Execution Order for DLL Lookup:
57
+
**Steps:**
54
58
55
-
In the course of the program's execution, it necessitates the specified dependencies (DLLs), which are identified and located by either the Integrated Development Environment (IDE) or the program's predetermined sequence. The pre-defined order of operations involves searching in the following locations:
59
+
* Open `Project Properties` (Right-click on the `Solution ` -> `Project Properties` in Visual Studio).
60
+
* Navigate to `Configuration Properties` -> `Debugging` -> `Working Directory`.
61
+
* Add the folder `(DLLs)` to specify that the project starts building from the `(DLLs)` folder instead of the root directory.
56
62
57
-
#### System Directory:
63
+
Running locally through (IDE) debugger:
58
64
59
-
The system directory, known as the system folder, location where the operating system initiates its search for the required DLL. This directory is an integral part of the operating system and contains crucial system files necessary for its functionality. If the DLL is located in this system directory and made publically accessible, the operating system promptly loads it to meet the program's requirements. The path to the system directory varies among operating systems, such as C:\Windows\System32 on Windows.
65
+
- Has no requirements as long as the DLLs are located there when they are asked by the application.
60
66
61
-
#### Root Directory (Current directory):
67
+
Running from Output Directory:
62
68
63
-
This root directory is typically where the main executable file (.exe) of the application resides. It is the top-level folder of the application's file structure and often represents the location where the application is installed or launched. If the required DLL is found within this root directory, it is prioritized over versions found in other locations, ensuring that the specific DLL required by the program takes precedence during execution.
69
+
- Requires the (DLL) directory to be built into the `output directory` for the `.exe` to locate it.
64
70
65
-
#### Defined Locations (PATH):
71
+
{: .note}
72
+
See the bottom of the page to setup `Pre-linking Events`.
66
73
67
-
The operating system extends its search to directories explicitly defined in the system PATH environment variable. The PATH variable contains a list of directories specified by the user or system administrator to enable convenient access to frequently used programs and libraries. These defined locations serve as a catalog of commonly utilized resources, and the operating system explores them in the specified order. If the required DLL is present in any of these PATH-defined directories, it is loaded, contributing to the seamless execution of the program.
74
+
**Advantages:**
68
75
69
-
[Source Documentation by Microsoft " Dynamic link library search order. "](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order)
76
+
- Allows the user to define a costum (DLL) folder up in one directory of the (Root directory).
77
+
- The project starts from the (DLL) folder.
70
78
79
+
**Cons:**
71
80
72
-
### Linking DLLs in Visual studio
81
+
- Requires that the user builds the folder into `output directory` aiming to run it from an .exe
82
+
- The user is limited to one folder of (DLLs), and can not define Debug from release versions.
73
83
74
-
Based on an (IDE) Visual Studio 2022, there are three ways of linking DLLs:
84
+
<br>
75
85
86
+
3.#### **Defined locations (PATH):**
76
87
77
-
#### System directory linking:
88
+
Giving the (IDE) or application a pre-defined location to look for dlls.
78
89
79
-
+ To Be Written.
80
-
+ Must be in the system files and made globally accessible.
90
+
The following should be used if the aim is to specify multiple location or versions of dlls for the application.
81
91
82
-
#### Root directory linking:
92
+
**Steps:**
83
93
84
-
- The DLLs are in the same directory as the .vcxproj are listed the core also known as root directory.
94
+
- Navigate to `Configuration Properties` -> `Debugging` -> `Environment`.
95
+
- Specify a path as an example `PATH=$(ProjectDir)\DLLs`, where `(ProjectDir)` specifies the project root and `\DLLs` its folder.
96
+
- This example the Working directory should be of `$(ProjectDir)` as listed in [Root Directory Linking (Default):](#root-directory-linking-default)
85
97
86
-
File structure (Root):
98
+
{: .note}
99
+
Specify more than one path `PATH=$(ProjectDir)\DLLs, PATH=$(ProjectDir)\DLLs2` by the use of `,`.
87
100
88
-
> Example.dll
89
-
>
90
-
> main.cpp
91
-
>
92
-
> Application.sln
93
-
>
94
-
> Application.vcxproj
95
-
>
96
-
> Application.vcxproj.user
97
-
>
98
-
> App.Tetris.vcxproj.filters
101
+
{: .note}
102
+
See the bottom of the page to setup Pre-linking Events.
103
+
104
+
**Advantages:**
105
+
106
+
- The user can define the locations of the `dlls`.
107
+
- The user is not limited to changing the working directory.
108
+
- The user can setup different `dlls` specific to debugging and release versions.
109
+
- Project organization and file handling.
110
+
111
+
**Cons:**
112
+
113
+
- Requires that the user builds the folder into `output directory` aiming to run it from an .exe (If located in a folder).
114
+
- Path has to be the same in `output directory` as in project files.
115
+
- May become difficult to remember the setup and how to change the specifics.
116
+
117
+
118
+
<br>
119
+
120
+
4.#### System directory linking:
121
+
122
+
{: .important}
123
+
The following is specific to the users machine, which may affect the project for collaboration and future development if the `dlls` are not made accessible in the system globally or not installed. <br><br>
124
+
Please use it with caution and existing knowledge as it requires `administrative privilages` and can potentionally lead to breaking your computer.
99
125
100
-
- Root linking the is beneficial for small projects as the developer is not required to link anything themseleves as the IDE does it for them.
126
+
The following should be used if and when for example you are testing your environments and projects on a local server, where additionally adding `dlls` may become unfavored.
101
127
102
-
- The issue: directory is messy and becomes hard to manage and to re-scale due to the files cluttering the resource and collaboration ineffectivness.
128
+
Remember the following should not be done for basic development environment!
103
129
104
-
+ !Change Root Directory.!
130
+
- Most commonly the following is used by companies that are known, that automatically install new `dlls` into your system, such alike for example `nvidia graphics drivers` is being handled as the following must be accessible not only by the gpu, but also any potential video games.
105
131
132
+
**Steps:**
106
133
107
-
#### Defined locations (PATH):
134
+
Access System Environment Variables:
108
135
136
+
1. Right-click on the Start button and select `System.`
137
+
2. Click on `Advanced system settings` on the left.
138
+
3. In the System Properties window, click the `Environment Variables` button.
139
+
4. Modify System's PATH Variable:
140
+
5. In the Environment Variables window, under the `System variables` section, find and select the `Path` variable.
141
+
6. Click the `Edit` button.
142
+
7. Add DLL Directory to PATH:
143
+
8. In the Edit Environment Variable window, click `New` and paste the full path to the directory containing your DLL.
144
+
9. Click `OK` to close each window.
145
+
146
+
{: .note}
147
+
When completed make sure to restart the system and or any applications you may have open.
148
+
149
+
{: .note}
150
+
If everything was done correctly, `visual studio` should now have access to globally linked dlls, this is because the search order of the (IDE) first takes through all of your `APIs`, `appplication`, `known dlls` and `dependencies`, if they aren ot found it looks for it through `system32``path`, <br><br>
151
+
Please see on further reading at the bottom of the page
152
+
153
+
**Advantages:**
154
+
155
+
- Makes your `dlls` accessible globally so that any project you make has access to them and avoid the setup each time.
156
+
- You can rely on your own local `dlls` if not specified differently by the project.
157
+
- One pre-defined location.
158
+
159
+
**Cons:**
160
+
161
+
- Can cause potential mishaps within the system due to defined `dlls`
162
+
- The `dlls` are only accessible locally.
163
+
- If the DLLs folder goes missing, every other project reliant on it breaks!
164
+
- Might cause issues with `dll` version as project(s) may require different patches.
- Use the Copy function to move files from the "DLLs" folder to the build root.
173
+
174
+
2.**Add the Following Command:**
175
+
176
+
{: .code}
177
+
```bash
178
+
copy "$(ProjectDir)DLLs*.dll""$(TargetDir)"
179
+
ping -n 6 127.0.0.1 > nul
180
+
```
181
+
2.1 Notes for Expanding
182
+
183
+
-`copy` function to copy all DLL files `(*.dll)` from the "DLLs" folder in your project directory `($(ProjectDir))` to the target directory where the final build is stored `($(TargetDir))`
184
+
- Adjust the file path according to the folder names based on Configuration steps 1 or 2.
185
+
-`.dll` Specifies that all with an extentsion of it should be added to the build.
186
+
187
+
- Specify further `copy` in the next line, depending on the amount of DLL dependencies change the ping of `-n 6`
188
+
- Alternativly the specification for specific `dll` can be called as such `copy "$(ProjectDir)DLLs\YourDLL1.dll" "$(TargetDir)"`, which instead using all in the directory calls the specified `.dll` file.
189
+
190
+
- ping -n 6 127.0.0.1 > nul
191
+
- Used to add additionaly day to ensure, that the project has sufficient time to link and build "dynamic libraries " DLLs
192
+
-`ping` command, essentially specifying a delay with amount.
193
+
-`-n 6` by 6 seconds
194
+
-`127.0.0.1 ` Loopback address, send loop to Address of 6 times with a delay of 6 seconds.
195
+
-`> nul` Supresses output from the display (Directing the output to void)
196
+
197
+
198
+
<br>
199
+
200
+
{: .further-reading}
201
+
And Example for Path and working directory [DLL In Folder Example](https://github.com/VerzatileDevOrg/VS.DLLinFolder) <br>
202
+
The following guide is based on an (IDE) [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) <br>
203
+
Visual studio [Build Events](https://learn.microsoft.com/en-us/visualstudio/ide/specifying-custom-build-events-in-visual-studio?view=vs-2022) <br> <br>
204
+
Read about `Working directory`[Source Documentation by Microsoft " Dynamic link library search order. "](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order)<br><br>
0 commit comments