问题引出:为什么要做成lib库? 1、不想将自己写的源代码公开,但是同时库文件又需要让别人能够正常调用,那封装成lib的格式就是一个方法。 2、编译某些工程文件时非常耗时,像ST官方的库时,由于文件众多,编译一次可能得1两分钟,这时可以打包成库,节省不少的时间。但同时也不能用右键go to Definition 'XXX’来直接找到源文件定义了。 如何生成LIB库文件? - 创建空工程,准备好生成LIB库文件对应的.c和.h文件,如
commLib.h: - //commLib.h:
- void delay(int ms);
- unsigned char ccCrol(unsigned char org, unsigned char bitNum);
- unsigned char ccCror(unsigned char org, unsigned char bitNum);
commLib.c: - //commLib.c:
- void delay(int ms)
- {
- .......
- }
- unsigned char ccCrol(unsigned char org, unsigned char bitNum)
- {
- .......
- }
- unsigned char ccCror(unsigned char org, unsigned char bitNum)
- {
- .......
- }
- 将这两个文件添加到项目中(只需要添加生成库所需要的头文件和源文件),并做以下设置:
选中Create Library

3. 编译之后在目录下生成对应的.LIB库文件了。

如何使用LIB库文件呢?
|