Tools, FAQ, Tutorials:
"MathClient.cpp" - Reference DLL Library
How to create and build a C++ application that reference a DLL library? I have the .h, .lib and .dll files of the library.
✍: FYIcenter.com
If you want to use a DLL library provided by others,
you can follow this tutorial:
1. Create the C++ source file, MathClient.cpp, with a text editor. Remember to include the MathFuncsLib.h file in the source code:
// MathClient.cpp : Defines the entry point for the console application.
// Compile by using: cl /EHsc /link MathLibrary.lib MathClient.cpp
#include "stdafx.h"
#include <iostream>
#include "MathLibrary.h"
using namespace std;
int main()
{
double a = 7.4;
int b = 99;
cout << "a + b = " <<
MathLibrary::Functions::Add(a, b) << endl;
cout << "a * b = " <<
MathLibrary::Functions::Multiply(a, b) << endl;
cout << "a + (a * b) = " <<
MathLibrary::Functions::AddMultiply(a, b) << endl;
return 0;
}
2. Compile MathClient.cpp into MathClient.obj with Visual Studio command "cl" with MathLibrary.h in the include path:
C:\fyicenter>cl /c /EHsc MathClient.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. MathClient.cpp C:\fyicenter>dir MathClient.* 11:06 AM 579 MathClient.cpp 11:10 AM 146,445 MathClient.obj
3. Build MathClient.obj into MathClient.exe with Visual Studio command "link" with MathLibrary.lib specified:
C:\fyicenter>link MathClient.obj MathLibrary.lib Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. C:\fyicenter>dir MathClient.* 11:06 AM 579 MathClient.cpp 11:13 AM 220,672 MathClient.exe 11:10 AM 146,445 MathClient.obj
4. Run MathClient.exe with MathLibrary.dll in the command path. Without MathLibrary.dll, you will see the MathLibrary.dll missing error.
C:\fyicenter>MathClient.exe a + b = 106.4 a * b = 732.6 a + (a * b) = 740
You can also compile and build MathClient.cpp into MathClient.exe with Visual Studio command "cl" directly with MathFuncsLib.lib specified. No need to run "link".
C:\fyicenter>cl /EHsc MathClient.cpp /link MathLibrary.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. MathClient.cpp Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:MathClient.exe MathLibrary.lib MathClient.obj C:\fyicenter>dir MathClient.* 11:06 AM 579 MathClient.cpp 11:20 AM 220,672 MathClient.exe 11:20 AM 146,445 MathClient.obj
⇒ Using .NET Framework in Visual Studio
⇐ "MathLibrary.cpp" - Build DLL Library
2023-05-31, ∼2305🔥, 2💬
Popular Posts:
How To Use an Array as a Queue in PHP? A queue is a simple data structure that manages data elements...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
Where can I download the EPUB 2.0 sample book "The Problems of Philosophy" by Lewis Theme? You can f...