- 簡單的靜態庫文件和測試
//庫文件.h
#pragma once
class MyMath
{
public:
MyMath();
~MyMath();
public:
int Add(int, int);
};
extern "C"
{
int Sub(int a, int b);
}
//庫文件.cpp
#include "stdafx.h"
#include "MyMath.h"
MyMath::MyMath()
{
}
MyMath::~MyMath()
{
}
int MyMath::Add(int a, int b)
{
return a + b;
}
int Sub(int a, int b)
{
return a - b;
}
//測試文件.h
#include "MyMath.h"
//測試文件.cpp
// TestStaticLib.cpp: 定義控制檯應用程序的入口點。
//
#include "stdafx.h"
#pragma comment (lib, "StaticLib1.lib")
class MyMath;
int main()
{
MyMath t;
t.Add(1, 4);
return 0;
}
測試用例:
靜態庫和動態庫的知識彙總:
1、靜態庫換成動態庫
2、實驗: DLL導出類依賴多個類時, 只提供一個頭文件的方法