在linux内核编程 不能include <stdio.h>的原因

<stdio.h>不是内核的库。在用户态的,而我们所在内核态。

内核调用的函数是编译进内核的;
应用层调用的是应用层的库;
两者对应的头文件目录不一致,不能搞混了,不然即使函数同名,运行也会出错。

另外,内核一般大小要求,不可能把一个2M的C库给链接在一起。

#include <errno.h> #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/resource.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <sys/mman.h> #include <rtdm/rtdm.h> #include <native/task.h> #include <native/sem.h> #include <native/mutex.h> #include <native/timer.h> #include <rtdk.h> #include <pthread.h> #include <math.h> #define PI 3.1415926535898 #include "ecrt.h" #define Bool int #define false 0 #define true 1 #define ETHERCAT_STATUS_OP 0x08 #define STATUS_SERVO_ENABLE_BIT (0x04) //master status typedef enum _SysWorkingStatus { SYS_WORKING_POWER_ON, SYS_WORKING_SAFE_MODE, SYS_WORKING_OP_MODE, SYS_WORKING_LINK_DOWN, SYS_WORKING_IDLE_STATUS //系统空闲 }SysWorkingStatus; typedef struct _GSysRunningParm { SysWorkingStatus m_gWorkStatus; }GSysRunningParm; GSysRunningParm gSysRunning; RT_TASK InterpolationTask; int run = 1; int ecstate = 0; #define CLOCK_TO_USE CLOCK_REALTIME #define NSEC_PER_SEC (1000000000L) #define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec) static int64_t system_time_base = 0LL; //获取当前系统时间 RTIME system_time_ns(void) { struct timespec rt_time; clock_gettime(CLOCK_TO_USE, &rt_time); RTIME time = TIMESPEC2NS(rt_time); return time - system_time_base; } /****************************************************************************/ // EtherCAT ec_master_t *master = NULL; static ec_master_state_t master_state = {}; static ec_domain_t *domainServoInput = NULL; static ec_domain_state_t domainServoInput_state = {}; static ec_domain_t *domainServoOutput = NULL; static ec_domain_state_t domainServoOutput_state = {}; static uint8_t *domainOutput_pd = NULL; static uint8_t *domainInput_pd = NULL; static ec_slave_config_t *sc_estun; static ec_slave_config_state_t sc_estun
03-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值