TI DSP C6657 Learning - Compiling static library .lib
[Copy link]
Friends who are familiar with C++ development know that we usually need to introduce many third-party compiled libraries into our code, some of which are static link libraries and some are dynamic link libraries. The purpose of introducing libraries is to reduce the compilation time of the code and to provide only function/method interfaces, which can effectively protect the source code from being leaked. The following will compile the static library .lib on DSP C6657
tool
- DSP C6657 EVM official evaluation board
- CCS8.1
- Windows 10 PC
Compile static library
think
The process of compiling static library on Visual Studio 2017:
- Create a new .h header file (write the function declaration)
- Create a new .cpp file (write the specific implementation of the function)
- In the project properties in vs2017, change the compilation output to static library
- Generate a solution and compile a .lib library file
- To test, create a new vs project, add .h and .lib to the project directory, include the .h file in cpp, and call the function directly.
The difference between compiling static libraries on DSP and Visual Studio is the same: both need to write .h, cpp files, and the project output is set to static library. The difference is that different compilers are used to compile cpp. vs2017 uses Microsoft C++ compiler to compile cpp, and gmake is used to compile cpp on DSP.
Compiling static libraries on DSP
Step 1: Create a new CCS Project
Notice:
Configuration items |
Configuration |
meaning |
Family |
C600 TMS320C6657 |
DSP Model |
Complier version |
TI v8.2.4 (according to CSS) |
Compiler version. CCS can set multiple versions of compilers. |
Output type |
Static Library (Important) |
The format of the compiled output file, select Static Library to compile the static library |
Device endianness |
little |
Memory endianness |
Project name: DSP6657_CompleLib
Step 2: Write the code for the library file
Let's first implement a simple function interface (return the sum of 2 integers):int add_test(int a,int b)
.h file--------function declaration
/*
* add_test.h
*
* Created on: 2018年8月22日
* Author: weiPenghui
*/
/*
* 测试编译静态库.lib文件
* 方法:
* step1:新建CCS工程时,将ToolChain设置为 static Library
* step2:编写.h,c文件
* step3:build生成.lib文件
*
* 总结:和windows上C/C++ lib编译的方法相似
*参考:https://blog.csdn.net/sphinz1/article/details/78817234
*/
#ifndef ADD_TEST_H_
#define ADD_TEST_H_
extern int add_test(int a,int b);
#endif /* ADD_TEST_H_ */
.c file----the specific implementation of the function
/*
* add_test.c
*
* Created on: 2018年8月22日
* Author: weiPenghui
*/
#include"add_test.h"
int add_test(int a,int b){
return a+b;
}
step3: compile and generate lib
Project->Build Project Generate lib static library in the project directory:
At this point, the .lib file has been successfully generated. Are you excited?
Test run
Create a new project and name it: DSP6657_TestComplieLib. Copy the .lib and .h files from the previous step to the root directory of the test project.
/**
* main.c
*/
#include<stdio.h>
#include<stdlib.h>
#include"add_test.h"
/*
* 测试调用编译好的静态库.lib
* 方法:将静态库文件.lib,头文件.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 it... Run results:
|