vs2013中静态库lib文件的生成与使用

本文介绍了如何在VS2013中生成静态库lib文件及如何在新项目中使用lib文件。首先创建CMath项目,包含CMath头文件和实现,生成Debug目录下的CMath.lib。然后在新项目中引入CMath.h和CMath.lib,设置附加库目录和附加依赖项,最后在CMain.h中调用库函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、静态库lib文件的生成

1.文件  --  新建项目  --  Visual C++  --  win32项目,输入项目名称,例如:CMath

2.项目右键  -- 添加 --  新建项

CMath.h 

class CMath

{

public:

CMath();

~CMath();

void setX(int x);

void setY(int y);

void print();

private:

int x;

int y;

};


CMath.cpp

#include "stdafx.h"

#include "CMath.h"

#include <iostream>

using namespace std;

CMath::CMath()

{

}

CMath::~CMath()

{

}

void CMath::setX(int x)

{

this->x = x;

}

void CMath::setY(int y)

{

this->y = y;

}

void CMath::print( )

{

cout << "x = " << x << ",y = " << y << endl;

}

3.生成  --  生成解决方案  

 Debug  目录下生成  CMath.lib 文件

 

二、静态库lib文件的使用

1.新建一个项目。

2.CMath.hCMath.lib拷贝到新项目目录下。

3.项目  --  右键属性  --  连接器  

     --  常规  --   附加库目录(把CMath.lib目录添加进去)

     --  输入  --  附加依赖项  (把CMath.lib添加进去)

4.CMain.h

#include "CMath.h"

#include <iostream>

using namespace std;

int main(int argc, char argv[])

{

CMath cmath;

cmath.setX(3);

cmath.setY(4);

cmath.print();

getchar();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值