Create a static library and use

1 Create a static lib project.

2 Create class.

.h file

// TestStaticLib.h: interface for the TestStaticLib class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TESTSTATICLIB_H__FBC7FEBA_1A54_4DBB_A54A_E12FA2266B93__INCLUDED_)
#define AFX_TESTSTATICLIB_H__FBC7FEBA_1A54_4DBB_A54A_E12FA2266B93__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

int Plus(int x, int y);
int Sub(int x, int y);
int Div (int x, int y);

#endif // !defined(AFX_TESTSTATICLIB_H__FBC7FEBA_1A54_4DBB_A54A_E12FA2266B93__INCLUDED_)

 

.cpp file

// TestStaticLib.cpp: implementation of the TestStaticLib class.
//
//////////////////////////////////////////////////////////////////////

#include "TestStaticLib.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

int Plus(int x, int y)
{
    return x+y;
}
int Sub(int x, int y)
{
    return x-y; 
} 
Int Div ( int x, int y) 
{ 
    return x / y; 
}

Compile successfully. TestStaticLib.h header files and get TestStaticLib.lib

2 use.

In the console program,

#include "stdafx.h"
#include <windows.h>
// 1 
#include "TestStaticLib.h"
// 2
#pragma comment(lib,"TestStaticLib.lib")

int main(int argc, char* argv[])
{
    //  3 调用函数
    int x = Plus(2,3);
    return 0;
}

Another use

The second step of the above do not, VC6 in, project- "setting-> Link inside, Object / library modules plus TestStaticLib.lib

Guess you like

Origin www.cnblogs.com/lan0725/p/11497466.html