码迷,mamicode.com
首页 > 编程语言 > 详细

Dev-C++中使用静态链接库

时间:2020-03-17 14:01:16      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:完成   argc   ++   idt   相同   main   pre   头文件   项目   

Dev-C++中使用静态链接库

在Dev-C++中,静态链接库的后缀是.a,这点和VS的lib不一样。

一、首先,我们建立静态链接库项目,
新建一个CPP文件square.cpp

code:

class Square{
public:
float Area(float width,float height);
};

float Square::Area(float width,float height){
return width * height;
}

这个类定义了计算长方形面积的方法。
编译无误即生成了和项目名相同的SquArea.a库文件。注意,这里不是代码文件名而是项目名。

二、使用静态库
新建一个控制台项目,新建一个头文件square.h
这里把上面定义的类粘贴过来:

code:

class Square{
public:
float Area(float width,float height);
};

在入口main.cpp里引用该头文件,

code:

#include <iostream>
#include "area.h"
using namespace std;

int main(int argc, char** argv) {
float width=0;
float height=0;
cout << "请输入长方形的宽:" << endl;
cin >> width;
cout << "请输入长方形的高:" << endl;
cin >> height;
Square square;
cout << "面积=" << square.Area(width,height) << endl;

system("pause");
return 0;

}

三、设置链接参数
进入项目属性参数设置,在链接栏增加下面
./Squarea.a

这里的意思是链接的时候把当前目录下Squarea静态链接库加入进来。

最后编译运行,完成。

Dev-C++中使用静态链接库

标签:完成   argc   ++   idt   相同   main   pre   头文件   项目   

原文地址:https://blog.51cto.com/1685766/2479173

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!