TI DSP C6657学习之——编译静态库.lib
[复制链接]
熟悉C++开发的的小伙伴都知道,我们一般代码中往往要引入许多第三方编译好的库,有些是静态链接库static library, 有些是动态链接库dll。引入库的目的一是减少代码的编译时间,二是只提供函数/方法接口,可以有效的保护源码不被泄露。下面将在DSP C6657上编译静态库.lib
工具
- DSP C6657 EVM官方评估板
- CCS8.1
- win10 PC
编译静态库
思考
Visual Studio 2017上编译静态库static library的过程:
- 新建一个.h头文件(写函数的声明)
- 新建一个.cpp文件(写函数的具体实现)
- 在vs2017中的工程属性中,将编译输出改为static library
- 生成解决方法,编译出.lib库文件
- 测试,新建一个vs工程,将.h和.lib加入工程目录,在cpp中包含.h文件,直接调用函数。
DSP上编译静态库和Visual Studio上的区别 相同之处:都要编写.h,cpp文件,工程输出设置为static library。不同之处:采用不同的complier编译cpp,vs2017采用Microsoft C++编译器编译cpp, DSP上采用gmake编译cpp。
DSP上编译静态库
step1:新建一个CCS Project
注意:
配置项 |
配置 |
含义 |
Family |
C600 TMS320C6657 |
DSP的型号 |
Complier version |
TI v8.2.4(根据CSS) |
编译器版本,CCS可以设置多个版本的编译器 |
Output type |
Static Library(重要) |
编译输出文件的格式,编译静态库选择Static Library |
Device endianness |
little |
内存的大小端 |
工程名称:DSP6657_CompleLib
step2:编写库文件的代码
我们先实现一个简单函数接口(返回2个整数之和): - int add_test(int a,int b)
.h文件--------函数的声明
-
-
-
-
-
- #ifndef ADD_TEST_H_
- #define ADD_TEST_H_
-
- extern int add_test(int a,int b);
-
-
-
-
- #endif /* ADD_TEST_H_ */
-
-
.c文件----函数的具体实现
-
-
- #include"add_test.h"
-
- int add_test(int a,int b){
-
- return a+b;
-
- }
-
-
step3:编译生成lib
Project->Build Project 在工程目录生成lib静态库:

至此,成功生成了.lib文件,很激动有木有!
测试运行
新建一个工程,取名:DSP6657_TestComplieLib。将上一步的.lib以及.h文件复制到测试工程的根目录。
-
- /**
- * main.c
- */
- #include<stdio.h>
- #include<stdlib.h>
- #include"add_test.h"
-
-
-
- int main(void)
- {
-
- int num1 = 10;
- int num2 = 12;
-
- int res = add_test(num1,num2);
-
- printf("num1=%d,num2=%d,res=%d\n",num1,num2,res);
-
- return 0;
- }
-
-
Run起来... 运行结果:
|