Tools, FAQ, Tutorials:
"MathFuncsLib.cpp" - Build Static Library
How to build a C++ static library with Visual Studio command tools?
✍: FYIcenter.com
The next step to create a static library is to create library source code and build the library .lib file as shown in this tutorial:
1. Create the C++ source file, MathFuncsLib.cpp, with a text editor:
// MathFuncsLib.cpp // compile with: cl /c /EHsc MathFuncsLib.cpp // post-build command: lib MathFuncsLib.obj #include "MathFuncsLib.h" #include <stdexcept> using namespace std; namespace MathFuncs { double MyMathFuncs::Add(double a, double b) { return a + b; } double MyMathFuncs::Subtract(double a, double b) { return a - b; } double MyMathFuncs::Multiply(double a, double b) { return a * b; } double MyMathFuncs::Divide(double a, double b) { return a / b; } }
2. Compile MathFuncsLib.cpp into MathFuncsLib.obj with Visual Studio command "cl":
C:\fyicenter>cl /c /EHsc MathFuncsLib.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. MathFuncsLib.cpp C:\fyicenter>dir MathFuncsLib.* 08:40 AM 578 MathFuncsLib.cpp 08:15 AM 413 MathFuncsLib.h 09:08 AM 1,025 MathFuncsLib.obj
3. Build MathFuncsLib.obj into MathFuncsLib.lib with Visual Studio command "lib":
C:\fyicenter>lib MathFuncsLib.obj Microsoft (R) Library Manager Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. C:\fyicenter>dir MathFuncsLib.* 08:40 AM 578 MathFuncsLib.cpp 08:15 AM 413 MathFuncsLib.h 09:12 AM 1,648 MathFuncsLib.lib 09:08 AM 1,025 MathFuncsLib.obj
4. Send two files to whoever wants to use your library:
⇒ "MyExecRefsLib.cpp" - Reference Static Library
⇐ "MathFuncsLib.h" - Header File of Static Library
2023-10-15, 1695🔥, 0💬
Popular Posts:
How to validate the id_token signature received from Azure AD v2.0 authentication response? You can ...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...
How to use the "@(...)" expression in Azure API Policy? The "@(...)" expression in Azure API Policy ...
How To Submit Values without Using a Form in PHP? If you know the values you want to submit, you can...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...