Two projects from Microsoft (Reference 1) are presented. MathLibrary project
generates a DLL file and a LIB file that are used by MathClient project.
DLLs are linked into a program at run time instead of build time.
Both Visual Studio 2022 projects contain cpp files
in Windows 11 environment. CUDA is not involved.
The Visual Studio 2022 project folder:
C:\Users\pm\source\repos
*** Outline ***
- MathLibrary project in MS Visual Studio 2022
- MathClient project in MS Visual Studio 2022
- References
MathLibrary project in MS Visual Studio 2022
- Launch Visual Studio 2022. In Get started sub-panel, click Open a new project.
- In Create a new project panel, select DLL (Universal Windows).
Click Next button.
- In Configure your new project panel:
Provid the name of the Project name: MathLibrary
Click Create button. - The Visual Studio editor appears with a dllmain.cpp file.
Four files are generated: dllmain.cpp, pch.cpp, pch.h, and framework.h - These four files are located in:
C:\Users\pm\source\repos\MathLibrary\MathLibrary
-
Right-click the folder of Header Files in Solution Explorer.
Select Add then New Item...
Add New Item - MathLibrary panel appears.
Select Header File (.h).
Provide the Name: MathLibrary.hClick Add button. - Open MathLibrary.h from Reference 1. Copy and paste its content into the source file MathLibrary.h.
-
Right-click the folder of Source Files in Solution Explorer.
Select Add then New Item...
Add New Item - MathLibrary panel appears.
Select C++ File (.cpp).
Provide the Name: MathLibrary.cppClick Add button. - Open MathLibrary.cpp from Reference 1. Copy and paste its content into the source file MathLibrary.cpp.
- Right click the file MathLibrary.cpp in Solution Explorer. Select Properties.
The Item Type is C/C++ compiler. Close the panel. - Right click the file MathLibrary.h in Solution Explorer. Select Properties.
The Item Type is C/C++ header. Close the panel. - Select Build menu then Build Solution.
- The MathLibrary project folder contains:
The files MathLibrary.dll and MathLibrary.lib are generated in the folder:
C:\Users\pm\source\repos\MathLibrary\x64\Debug
MathClient project in MS Visual Studio 2022
- Launch Visual Studio 2022.
In Get started sub-panel, click Create a new project. - In Create a new project panel, select Console App.
Click Next button. - In Configure your new project panel,
provid the name of the project: MathClient
Click Create button. - The Visual Studio editor appears.
- The Visual Studio 2022 project folder contains two folders:
- Open MathClient.cpp from Reference 1. Copy and paste its content into the source file MathClient.cpp.
- *********************************************
Add MathLibrary.h to MathClient project
********************************************* - Right click the project MathClient in Solution Explorer.
Select Properties.
MathClient Property Pages appears.
Select C/C++ then General.
Add ..\..\MathLibrary\MathLibrary in Additional Include Directories.Click Apply button then OK button. - **************************************************************
Add MathLibrary.lib and its folder to MathClient project
************************************************************** - Right click the project MathClient in Solution Explorer.
Select Properties.
MathClient Property Pages appears.
Select Linker then Input.
Add MathLibrary.lib; in Additional Dependencies.Click Apply button then OK button. - Right click the project MathClient in Solution Explorer.
Select Properties.
MathClient Property Pages appears.
Select Linker then General.
Add ..\..\MathLibrary\$(IntDir) in Additional Library Directories.Click Apply button then OK button. - ******************************************************
Copy MathLibrary.dll from its MathLibrary folder
into MathClient project
****************************************************** - Right click the project MathClient in Solution Explorer.
Select Properties.
MathClient Property Pages appears.
Select Build Events then Post-Build Event.
Add xcopy /y /d "..\..\MathLibrary\$(IntDir)MathLibrary.dll" "$(OutDir)" in Command Line.Click Apply button then OK button. - Select Debug menu then Start Without Debugging
- Visual Studio 2022 editor looks like:
- The MathClient project folder contains:
References
- Microsoft: Walkthrough: Create and use your own Dynamic Link Library (C++) with Visual Studio 2022
- National Instruments: Building a DLL with Visual C++
- wikiHow: How to create DLL files