Lib文件的调用:
1.生成的Lib文件和对应的头文件[MyStaticLib.h StaticLib.lib]复制到工程目录
2.将2个文件[MyStaticLib.h StaticLib.lib]导入工程
1 #include <iostream> 2 #include "MyStaticLib.h" 3 using namespace std; 4 #pragma comment(lib,"StaticLib") 5 int main() 6 { 7 int m = 700, n = 360; 8 cout << "MaxCommDiv: " << GetMaxCommDiv(m, n) << endl; 9 cout << "MinCommMul: " << GetMinCommMul(m, n) << endl; 10 }
Lib文件的制作:
VS2019桌面向导-应用程序类型:Lib静态库 空项目
1 //MyStaticLib.h 2 #pragma once 3 int GetMaxCommDiv(int a, int b); 4 int GetMinCommMul(int a, int b);
1 //MyStaticLib.cpp 2 #include "MyStaticLib.h" 3 4 int GetMaxCommDiv(int a, int b) 5 { 6 int x = 1; 7 int ires; 8 if (a < b) 9 return 0; 10 if (b == 0) 11 return 0; 12 while (x != 0) 13 { 14 x = a % b; 15 a = b; 16 ires = b; 17 b = x; 18 } 19 return ires; 20 } 21 22 int GetMinCommMul(int a, int b) 23 { 24 int x = 1; 25 int ires; 26 int m, n; 27 m = a; n = b; 28 if (a < b) 29 return 0; 30 if (a == 0) 31 return 0; 32 if (b == 0) 33 return 0; 34 while (x != 0) 35 { 36 x = a % b; 37 a = b; 38 ires = b; 39 b = x; 40 } 41 ires = (m * n) / ires; 42 return ires; 43 }
标签:return,lib,Lib,int,ires,C++,实例,MyStaticLib From: https://www.cnblogs.com/kaling/p/17118559.html