Tools, FAQ, Tutorials:
"MyExecRefsLib.cpp" - Reference Static Library
How to create and build a C++ application that reference a static library? I have the .h and .lib files of the library.
✍: FYIcenter.com
If you want to use a static library provided by others, you can follow this tutorial:
1. Create the C++ source file, MyExecRefsLib.cpp, with a text editor. Remember to include the MathFuncsLib.h file in the source code:
// MyExecRefsLib.cpp // compile with: cl /EHsc MyExecRefsLib.cpp /link MathFuncsLib.lib #include <iostream> #include "MathFuncsLib.h" using namespace std; int main() { double a = 7.4; int b = 99; cout << "a + b = " << MathFuncs::MyMathFuncs::Add(a, b) << endl; cout << "a - b = " << MathFuncs::MyMathFuncs::Subtract(a, b) << endl; cout << "a * b = " << MathFuncs::MyMathFuncs::Multiply(a, b) << endl; cout << "a / b = " << MathFuncs::MyMathFuncs::Divide(a, b) << endl; return 0; }
2. Compile MyExecRefsLib.cpp into MyExecRefsLib.obj with Visual Studio command "cl" with MathFuncsLib.h in the include path:
C:\fyicenter>cl /c /EHsc MyExecRefsLib.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. MyExecRefsLib.cpp C:\fyicenter>dir MyExecRefsLib.* 09:23 AM 568 MyExecRefsLib.cpp 09:26 AM 146,650 MyExecRefsLib.obj
3. Build MyExecRefsLib.obj into MyExecRefsLib.exe with Visual Studio command "link" with MathFuncsLib.lib specified:
C:\fyicenter>link MyExecRefsLib.obj MathFuncsLib.lib Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. C:\fyicenter>dir MyExecRefsLib.* 09:23 AM 568 MyExecRefsLib.cpp 09:30 AM 220,160 MyExecRefsLib.exe 09:26 AM 146,650 MyExecRefsLib.obj
4. Run MyExecRefsLib.exe without any other files:
C:\fyicenter>MyExecRefsLib.exe a + b = 106.4 a - b = -91.6 a * b = 732.6 a / b = 0.0747475
You can also compile and build MyExecRefsLib.cpp into MyExecRefsLib.exe with Visual Studio command "cl" directly with MathFuncsLib.lib specified. No need to run "link".
C:\fyicenter>cl /EHsc MyExecRefsLib.cpp /link MathFuncsLib.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. MyExecRefsLib.cpp Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:MyExecRefsLib.exe MathFuncsLib.lib MyExecRefsLib.obj C:\fyicenter>dir MyExecRefsLib.* 09:23 AM 568 MyExecRefsLib.cpp 09:35 AM 220,160 MyExecRefsLib.exe 09:35 AM 146,650 MyExecRefsLib.obj
⇒ "MathLibrary.h" - Header File of DLL Library
⇐ "MathFuncsLib.cpp" - Build Static Library
2023-10-15, 1577🔥, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
What is Azure API Management Developer Portal? Azure API Management Developer Portal is an Azure Web...