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 2015 projects contain cpp files
in Windows 10 X64 environment. CUDA is not involved.
*** Outline ***
- MathLibrary project in MS Visual Studio 2015
- MathClient project in MS Visual Studio 2015
- References
MathLibrary project in MS Visual Studio 2015
- In Start Page - Microsoft Visual Studio, select New Project...
- Select Win32 Console Application.
Provid the name of the project: MathLibrary.
Click OK button. - Welcome to the Win32 Application Wizard panel appears. Click Next > button.
- Application Settings panel appears. Tick DLL for Application type.
Click Finish button. - The Visual Studio editor appears.
Five files are generated: stdafx.h, targetver.h, stdafx.cpp, dllmain.cpp, and an empty MathLibrary.cpp file. - Select x64 platform.
- The project folder contains:
- Open MathLibrary.cpp from Reference 1. Copy and paste its content into the source file MathLibrary.cpp.
- Right click the folder of Header Files in Solution Explorer for adding a new item. Select Add then New Item...
- Select Header File(.h).
Provid the name of Header File(.h): MathLibrary.h. The file extension is .h.Click Add button. An source file appears for editing. - Open MathLibrary.h from Reference 1. Copy and paste its content into the source file MathLibrary.h.
- 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 project folder contains:
The files MathLibrary.dll and MathLibrary.lib are generated in the folder C:\Users\Papa\Documents\Visual Studio 2015\Projects\MathLibrary\x64\Debug.
MathClient project in MS Visual Studio 2015
- In Start Page, select New Project...
- Select Win32 Console Application.
Provid the name of the project: MathClient.
Click OK button. - Welcome to the Win32 Application Wizard panel appears. Click Next > button.
- Application Settings panel appears. Select Empty project then click Finish button.
- The Visual Studio editor appears.
- Select x64 platform.
- Right click the folder of Source Files in Solution Explorer for adding a new item. Select Add then New Item...
- Provid the name of Visual C++ File(.cpp): MathClient.cpp.
Click Add button. - An empty source file appears for editing.
- Open MathClient.cpp from Reference 1. Copy and paste its content into the source file MathClient.cpp.
- Right click the folder of Header Files in Solution Explorer for adding a new item. Select Add then New Item...
- Select Header File(.h).
Provid the name of Header File(.h): MathLibrary.h. Click Add button. An source file appears for editing. - Open MathLibrary.h from Reference 1. Copy and paste its content into the source file MathLibrary.h.
- Copy the file MathLibrary.lib from the folder C:\Users\Papa\Documents\Visual Studio 2015\Projects\MathLibrary\x64\Debug. Paste it into the folder C:\Users\Papa\Documents\Visual Studio 2015\Projects\MathClient\MathClient.
- The project folder contains:
- Visual Studio 2015 editor looks like:
- Right click the project MathClient in
Solution Explorer. Select Properties, Linker, and Input. Add
MathLibrary.lib; in Additional Dependencies.
Click the mouse for activing Appliquer button.
Click Appliquer button then OK button. - Select Build menu then Rebuild Solution.
- The project folder contains:
- Select and copy the file MathLibrary.dll from the folder
C:\Users\Papa\Documents\Visual Studio 2015\Projects\MathLibrary\x64\Debug.
Paste it into the folder
C:\Users\Papa\Documents\Visual Studio 2015\Projects\MathClient\x64\Debug.
- Select Debug menu then Start Without Debugging
References
- Microsoft: Walkthrough: Create and use your own Dynamic Link Library (C++) with Visual Studio 2015
- National Instruments: Building a DLL with Visual C++
- wikiHow: How to create DLL files