靜態庫和動態庫應用匯總

  1.  簡單的靜態庫文件和測試
//庫文件.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導出類依賴多個類時, 只提供一個頭文件的方法

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章