Dev-C++中使用静态连接库ios
在Dev-C++中,静态连接库的后缀是.a,这点和VS的lib不同。markdown
1、首先,咱们创建静态连接库项目,
新建一个CPP文件square.cppide
code:spa
class Square{
public:
float Area(float width,float height);
};code
float Square::Area(float width,float height){
return width * height;
}ci
这个类定义了计算长方形面积的方法。
编译无误即生成了和项目名相同的SquArea.a库文件。注意,这里不是代码文件名而是项目名。it
2、使用静态库
新建一个控制台项目,新建一个头文件square.h
这里把上面定义的类粘贴过来:io
code:编译
class Square{
public:
float Area(float width,float height);
};class
在入口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;
}
3、设置连接参数
进入项目属性参数设置,在连接栏增长下面
./Squarea.a
这里的意思是连接的时候把当前目录下Squarea静态连接库加入进来。
最后编译运行,完成。