error: variable has incomplete type ‘struct sched_param‘ struct sched_param param = { .sched

Linux内核版本升级给开发者带来不便,安卓基于此内核也影响开发者。文中提到4.19内核编译报错情况,给出了添加相关定义的解决办法,如包含特定头文件并根据内核版本进行条件判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Linux内核版本升级变更给开发者带来诸多不便,安卓建立在内核之上,同样对开发者造成困扰。不断的版本升级更新,让众多开发人员疲于追随,也许这就是普通程序员宿命吧。

  4.19内核编译报错 :error: variable has incomplete type 'struct sched_param'         struct sched_param param = { .sched_priority

 添加下面定义即可。

#include <linux/version.h>

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
#include <uapi/linux/sched/types.h> // struct sched_param
#include <linux/sched/types.h> // sched_setscheduler
#endif

main.c: In function ‘cyclic_task’: main.c:66:3: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration] 66 | clock_gettime(CLOCK_TO_USE, &wakeupTime); | ^~~~~~~~~~~~~ main.c:66:17: error: ‘CLOCK_TO_USE’ undeclared (first use in this function) 66 | clock_gettime(CLOCK_TO_USE, &wakeupTime); | ^~~~~~~~~~~~ main.c:66:17: note: each undeclared identifier is reported only once for each function it appears in main.c:69:18: warning: implicit declaration of function ‘timespec_add’ [-Wimplicit-function-declaration] 69 | wakeupTime = timespec_add(wakeupTime, cycletime); | ^~~~~~~~~~~~ main.c:69:43: error: ‘cycletime’ undeclared (first use in this function) 69 | wakeupTime = timespec_add(wakeupTime, cycletime); | ^~~~~~~~~ main.c:70:5: warning: implicit declaration of function ‘clock_nanosleep’ [-Wimplicit-function-declaration] 70 | clock_nanosleep(CLOCK_TO_USE, TIMER_ABSTIME, &wakeupTime, NULL); | ^~~~~~~~~~~~~~~ main.c:70:35: error: ‘TIMER_ABSTIME’ undeclared (first use in this function) 70 | clock_nanosleep(CLOCK_TO_USE, TIMER_ABSTIME, &wakeupTime, NULL); | ^~~~~~~~~~~~~ main.c:77:42: warning: implicit declaration of function ‘TIMESPEC2NS’ [-Wimplicit-function-declaration] 77 | ecrt_master_application_time(master, TIMESPEC2NS(wakeupTime)); | ^~~~~~~~~~~ main.c:108:25: error: ‘domain1’ undeclared (first use in this function) 108 | ecrt_domain_process(domain1); | ^~~~~~~ main.c:111:5: warning: implicit declaration of function ‘check_master_state’; did you mean ‘ecrt_master_state’? [-Wimplicit-function-declaration] 111 | check_master_state(); | ^~~~~~~~~~~~~~~~~~ | ecrt_master_state main.c:112:5: warning: implicit declaration of function ‘check_domain1_state’; did you mean ‘ecrt_domain_state’? [-Wimplicit-function-declaration] 112 | check_domain1_state(); | ^~~~~~~~~~~~~~~~~~~ | ecrt_domain_state main.c:113:5: warning: implicit declaration of function ‘check_slave_config_states’; did you mean ‘ecrt_slave_config_state’? [-Wimplicit-function-declaration] 113 | check_slave_config_states(); | ^~~~~~~~~~~~~~~~~~~~~~~~~ | ecrt_slave_config_state In file included from main.c:12: main.c:115:48: error: ‘domain1_pd’ undeclared (first use in this function) 115 | uint16_t current_status_word = EC_READ_U16(domain1_pd + status_word); | ^~~~~~~~~~ ../../include/ecrt.h:2877:24: note: in definition of macro ‘le16_to_cpu’ 2877 | #define le16_to_cpu(x) x | ^ ../../include/ecrt.h:2949:18: note: in expansion of macro ‘le16_to_cpup’ 2949 | ((uint16_t) le16_to_cpup((void *) (DATA))) | ^~~~~~~~~~~~ main.c:115:36: note: in expansion of macro ‘EC_READ_U16’ 115 | uint16_t current_status_word = EC_READ_U16(domain1_pd + status_word); | ^~~~~~~~~~~ main.c:115:61: error: ‘status_word’ undeclared (first use in this function) 115 | uint16_t current_status_word = EC_READ_U16(domain1_pd + status_word); | ^~~~~~~~~~~ ../../include/ecrt.h:2877:24: note: in definition of macro ‘le16_to_cpu’ 2877 | #define le16_to_cpu(x) x | ^ ../../include/ecrt.h:2949:18: note: in expansion of macro ‘le16_to_cpup’ 2949 | ((uint16_t) le16_to_cpup((void *) (DATA))) | ^~~~~~~~~~~~ main.c:115:36: note: in expansion of macro ‘EC_READ_U16’ 115 | uint16_t current_status_word = EC_READ_U16(domain1_pd + status_word); | ^~~~~~~~~~~ main.c:116:51: error: ‘target_position’ undeclared (first use in this function); did you mean ‘target_pos_b’? 116 | int32_t actual_pos = EC_READ_S32(domain1_pd + target_position); // 或者实际位置反馈的偏移 | ^~~~~~~~~~~~~~~ ../../include/ecrt.h:2878:24: note: in definition of macro ‘le32_to_cpu’ 2878 | #define le32_to_cpu(x) x | ^ ../../include/ecrt.h:2973:17: note: in expansion of macro ‘le32_to_cpup’ 2973 | ((int32_t) le32_to_cpup((void *) (DATA))) | ^~~~~~~~~~~~ main.c:116:26: note: in expansion of macro ‘EC_READ_S32’ 116 | int32_t actual_pos = EC_READ_S32(domain1_pd + target_position); // 或者实际位置反馈的偏移 | ^~~~~~~~~~~ main.c:117:9: error: ‘counter’ undeclared (first use in this function); did you mean ‘count’? 117 | if (counter) { | ^~~~~~~ | count main.c:139:7: error: ‘blink’ undeclared (first use in this function); did you mean ‘link’? 139 | blink = !blink; | ^~~~~ | link main.c:147:9: error: ‘sync_ref_counter’ undeclared (first use in this function) 147 | if (sync_ref_counter) { | ^~~~~~~~~~~~~~~~ In file included from main.c:12: main.c:158:35: error: ‘control_word’ undeclared (first use in this function) 158 | EC_WRITE_U16(domain1_pd + control_word, 0x0006); | ^~~~~~~~~~~~ ../../include/ecrt.h:3059:25: note: in definition of macro ‘EC_WRITE_U16’ 3059 | *((uint16_t *) (DATA)) = cpu_to_le16((uint16_t) (VAL)); \ | ^~~~ main.c:176:57: error: ‘actual_position’ undeclared (first use in this function); did you mean ‘actual_position_’? 176 | int32_t actual_position_ = EC_READ_S32(domain1_pd + actual_position); | ^~~~~~~~~~~~~~~ ../../include/ecrt.h:2878:24: note: in definition of macro ‘le32_to_cpu’ 2878 | #define le32_to_cpu(x) x | ^ ../../include/ecrt.h:2973:17: note: in expansion of macro ‘le32_to_cpup’ 2973 | ((int32_t) le32_to_cpup((void *) (DATA))) | ^~~~~~~~~~~~ main.c:176:32: note: in expansion of macro ‘EC_READ_S32’ 176 | int32_t actual_position_ = EC_READ_S32(domain1_pd + actual_position); | ^~~~~~~~~~~ main.c:116:13: warning: unused variable ‘actual_pos’ [-Wunused-variable] 116 | int32_t actual_pos = EC_READ_S32(domain1_pd + target_position); // 或者实际位置反馈的偏移 | ^~~~~~~~~~ main.c: In function ‘main’: main.c:209:5: warning: implicit declaration of function ‘mlockall’ [-Wimplicit-function-declaration] 209 | if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) { | ^~~~~~~~ main.c:209:14: error: ‘MCL_CURRENT’ undeclared (first use in this function) 209 | if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) { | ^~~~~~~~~~~ main.c:209:28: error: ‘MCL_FUTURE’ undeclared (first use in this function) 209 | if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) { | ^~~~~~~~~~ main.c:217:2: error: ‘domain1’ undeclared (first use in this function); did you mean ‘main’? 217 | domain1 = ecrt_master_create_domain(master); | ^~~~~~~ | main main.c:221:2: error: ‘sc’ undeclared (first use in this function); did you mean ‘sync’? 221 | sc = ecrt_master_slave_config(master, SV660NPos, SV660N_PIDVID); | ^~ | sync main.c:223:40: error: ‘slave_0_syncs’ undeclared (first use in this function) 223 | if (ecrt_slave_config_pdos(sc, EC_END, slave_0_syncs)) { | ^~~~~~~~~~~~~ main.c:228:46: error: ‘domain1_regs’ undeclared (first use in this function) 228 | if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { | ^~~~~~~~~~~~ main.c:232:34: error: ‘PERIOD_NS’ undeclared (first use in this function) 232 | ecrt_slave_config_dc(sc, 0x0300, PERIOD_NS, 0, 0, 0); | ^~~~~~~~~ main.c:237:8: error: ‘domain1_pd’ undeclared (first use in this function) 237 | if (!(domain1_pd = ecrt_domain_data(domain1))) { | ^~~~~~~~~~ main.c:240:8: error: variableparamhas initializer but incomplete type 240 | struct sched_param param = {}; | ^~~~~~~~~~~ main.c:240:20: error: storage size of ‘param’ isn’t known 240 | struct sched_param param = {}; | ^~~~~ main.c:241:25: warning: implicit declaration of function ‘sched_get_priority_max’ [-Wimplicit-function-declaration] 241 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); | ^~~~~~~~~~~~~~~~~~~~~~ main.c:241:48: error:SCHED_FIFO’ undeclared (first use in this function) 241 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); | ^~~~~~~~~~ main.c:244:6: warning: implicit declaration of function ‘sched_setscheduler’ [-Wimplicit-function-declaration] 244 | if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) { | ^~~~~~~~~~~~~~~~~~ main.c:240:20: warning: unused variableparam’ [-Wunused-variable] 240 | struct sched_param param = {}; | ^~~~~ At top level: main.c:43:17: warning: ‘domainInput_pd’ defined but not used [-Wunused-variable] 43 | static uint8_t *domainInput_pd = NULL; | ^~~~~~~~~~~~~~ main.c:42:17: warning: ‘domainOutput_pd’ defined but not used [-Wunused-variable] 42 | static uint8_t *domainOutput_pd = NULL; | ^~~~~~~~~~~~~~~ main.c:37:21: warning: ‘user_alarms’ defined but not used [-Wunused-variable] 37 | static unsigned int user_alarms = 0; | ^~~~~~~~~~~ main.c:36:21: warning: ‘sig_alarms’ defined but not used [-Wunused-variable] 36 | static unsigned int sig_alarms = 0; | ^~~~~~~~~~ main.c:33:32: warning: ‘sc_motor_state’ defined but not used [-Wunused-variable] 33 | static ec_slave_config_state_t sc_motor_state = {}; | ^~~~~~~~~~~~~~ main.c:32:27: warning: ‘sc_motor’ defined but not used [-Wunused-variable] 32 | static ec_slave_config_t *sc_motor = NULL; | ^~~~~~~~ main.c:30:26: warning: ‘domainOutput_state’ defined but not used [-Wunused-variable] 30 | static ec_domain_state_t domainOutput_state = {}; | ^~~~~~~~~~~~~~~~~~ main.c:29:21: warning: ‘domainOutput’ defined but not used [-Wunused-variable] 29 | static ec_domain_t *domainOutput = NULL; | ^~~~~~~~~~~~ main.c:27:26: warning: ‘domainInput_state’ defined but not used [-Wunused-variable] 27 | static ec_domain_state_t domainInput_state = {}; | ^~~~~~~~~~~~~~~~~ main.c:26:21: warning: ‘domainInput’ defined but not used [-Wunused-variable] 26 | static ec_domain_t *domainInput = NULL; | ^~~~~~~~~~~ main.c:24:26: warning: ‘master_state’ defined but not used [-Wunused-variable] 24 | static ec_master_state_t master_state = {}; | ^~~~~~~~~~~~ make: *** [Makefile:333:ec_user_example-main.o] 错误 1
最新发布
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值