Main.c
中代码库
//....
#include "BMS.c"
//....
struct BMS_dev{
// specific to each battery pack
char err[16];
//.....
bool b_lim ;
};
//....
// other constants & variables declared
//....
int main(){ // setup and configure
char b = 0;
char dev;
//......
//more code
//....
b = hello_all();
struct BMS_dev pack[b]; // Array of structures declared here, b could be 1 ,2, 3, 4
//......
for (dev=0;dev<b;dev++){ // main loop of program cycles through each device, 0 .. b
char h = 0;
id[dev] = 0;
//.....
v_cell_d(&pack[dev]); // function v_cell_d is called, passing reference to pack[b]
// ...
//rest of main.//
:
BMS.c
该程序的编译为:
bool v_cell_d(struct BMS_dev *pp){
//vc_del = 0;
pp->vc_max = 0;
pp->vc_min = 4;
float lim_low = 2.75 ;//#V
float lim_high = 3.58 ;//#V
pp->b_lim = false;
//......
return(pp->b_lim) ;
}
计算机错误:
gcc -g main.c -l sqlite3 -o Max10 -lm
第一个错误是由于试图告诉编译器
In file included from main.c:14:
BMS.c:13:15: warning: useless storage class specifier in empty declaration
13 | extern struct BMS_dev;
| ^~~~~~~
BMS.c: In function ‘v_cell_d’:
BMS.c:157:7: error: invalid use of undefined type ‘struct BMS_dev’
157 | pp->vc_max = 0;
| ^~
BMS.c:158:7: error: invalid use of undefined type ‘struct BMS_dev’
158 | pp->vc_min = 4;
| ^~
BMS.c:161:7: error: invalid use of undefined type ‘struct BMS_dev’
161 | pp->b_lim = false;
的结构在其他地方(在*pp
)中声明;没有此,它假设我试图在函数变量列表中声明结构。
我如何做这项工作?
没有您的文件,只有
main.c
文件。您用于构建程序的命令应指定所有
#include
文件,然后将它们链接在一起以生成.c
.h
的定义不属于
.c
,它应该在一个单独的
.exe
文件中,然后可以在
struct BMS_dev
和
main.c
/中。
.h
.