Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
libmodbus
RT-Thread
编译问题
RT-Thread 应用笔记 - libmodbus RTU 编译问题的解决
发布于 2021-12-24 23:47:21 浏览:2945
订阅该版
[tocm] [RT-Thread 入门学习笔记 - 目录](https://club.rt-thread.org/ask/article/3420.html) ## 前言 - 更新最新的RT-Thread 标准版后,发现libmodbus软件包,无法正常编译通过 - 使用RT-Thread Studio编译,gcc的无法编译通过 - 使用Keil MDK5编译,依旧是编译不通过 ## Keil MDK5 解决方法 - 这里使用RT-Thread中的随意一个BSP:如`rt-thread\bsp\stm32\stm32l475-atk-pandora` - menuconfig配置,默认配置皆可 - `scons --target=mdk5`构建工程,确保默认工程可以正常的编译 ![2021-12-24_085425.png](https://oss-club.rt-thread.org/uploads/20211224/4f232f9407e001c5e9ee33f86c41e37b.png) - 开启`libmodbus`软件包,这里使用RTU模式,手动把软件包的例程copy到工程中 ![2021-12-24_085624.png](https://oss-club.rt-thread.org/uploads/20211224/093963e7cfb6fe45c52c169baa611220.png) - `pkgs --update`下载libmodbus软件包到本地 - 重新构建工程,编译发现无法通过 ```c Build started: Project: project *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'rt-thread' compiling modbus.c... packages\libmodbus-latest\inc\modbus-private.h(84): error: #20: identifier "fd_set" is undefined int (*select) (modbus_t *ctx, fd_set *rset, struct timeval *tv, int msg_length); packages\libmodbus-latest\src\modbus.c(150): warning: #68-D: integer conversion resulted in a change of sign return MSG_LENGTH_UNDEFINED; packages\libmodbus-latest\src\modbus.c(184): error: #20: identifier "EBADF" is undefined if ((errno == EBADF || errno == ECONNRESET || errno == EPIPE)) { packages\libmodbus-latest\src\modbus.c(184): error: #20: identifier "ECONNRESET" is undefined if ((errno == EBADF || errno == ECONNRESET || errno == EPIPE)) { packages\libmodbus-latest\src\modbus.c(184): error: #20: identifier "EPIPE" is undefined if ((errno == EBADF || errno == ECONNRESET || errno == EPIPE)) { packages\libmodbus-latest\src\modbus.c(339): error: #20: identifier "fd_set" is undefined fd_set rset; packages\libmodbus-latest\src\modbus.c(355): warning: #223-D: function "FD_ZERO" declared implicitly FD_ZERO(&rset); packages\libmodbus-latest\src\modbus.c(356): warning: #223-D: function "FD_SET" declared implicitly FD_SET(ctx->s, &rset); packages\libmodbus-latest\src\modbus.c(381): error: #20: identifier "ETIMEDOUT" is undefined if (errno == ETIMEDOUT) { packages\libmodbus-latest\src\modbus.c(384): error: #20: identifier "EBADF" is undefined } else if (errno == EBADF) { packages\libmodbus-latest\src\modbus.c(395): error: #20: identifier "ECONNRESET" is undefined errno = ECONNRESET; packages\libmodbus-latest\src\modbus.c(402): error: #20: identifier "ECONNRESET" is undefined (errno == ECONNRESET || errno == ECONNREFUSED || packages\libmodbus-latest\src\modbus.c(402): error: #20: identifier "ECONNREFUSED" is undefined (errno == ECONNRESET || errno == ECONNREFUSED || packages\libmodbus-latest\src\modbus.c(403): error: #20: identifier "EBADF" is undefined errno == EBADF)) { packages\libmodbus-latest\src\modbus.c(910): error: #20: identifier "ENOPROTOOPT" is undefined errno = ENOPROTOOPT; packages\libmodbus-latest\src\modbus.c(912): warning: #111-D: statement is unreachable break; packages\libmodbus-latest\src\modbus.c: 4 warnings, 12 errors compiling modbus-rtu.c... packages\libmodbus-latest\src\modbus-rtu.c(18): error: #5: cannot open source input file "dfs_select.h": No such file or directory #include
packages\libmodbus-latest\src\modbus-rtu.c: 0 warnings, 1 error compiling serial.c... ..\..\..\components\drivers\serial\serial.c(890): error: #20: identifier "speed_t" is undefined speed_t speed; ..\..\..\components\drivers\serial\serial.c(896): error: #20: identifier "B2400" is undefined {B2400, BAUD_RATE_2400}, ..\..\..\components\drivers\serial\serial.c(897): error: #20: identifier "B4800" is undefined {B4800, BAUD_RATE_4800}, ..\..\..\components\drivers\serial\serial.c(898): error: #20: identifier "B9600" is undefined {B9600, BAUD_RATE_9600}, ..\..\..\components\drivers\serial\serial.c(899): error: #20: identifier "B19200" is undefined {B19200, BAUD_RATE_19200}, ..\..\..\components\drivers\serial\serial.c(900): error: #20: identifier "B38400" is undefined {B38400, BAUD_RATE_38400}, ..\..\..\components\drivers\serial\serial.c(901): error: #20: identifier "B57600" is undefined {B57600, BAUD_RATE_57600}, ..\..\..\components\drivers\serial\serial.c(902): error: #20: identifier "B115200" is undefined {B115200, BAUD_RATE_115200}, ..\..\..\components\drivers\serial\serial.c(903): error: #20: identifier "B230400" is undefined {B230400, BAUD_RATE_230400}, ..\..\..\components\drivers\serial\serial.c(904): error: #20: identifier "B460800" is undefined {B460800, BAUD_RATE_460800}, ..\..\..\components\drivers\serial\serial.c(905): error: #20: identifier "B921600" is undefined {B921600, BAUD_RATE_921600}, ..\..\..\components\drivers\serial\serial.c(906): error: #20: identifier "B2000000" is undefined {B2000000, BAUD_RATE_2000000}, ..\..\..\components\drivers\serial\serial.c(907): error: #20: identifier "B3000000" is undefined {B3000000, BAUD_RATE_3000000}, ..\..\..\components\drivers\serial\serial.c(910): error: #20: identifier "speed_t" is undefined static speed_t _get_speed(int baudrate) ..\..\..\components\drivers\serial\serial.c(920): error: #20: identifier "B0" is undefined return B0; ..\..\..\components\drivers\serial\serial.c(923): error: #20: identifier "speed_t" is undefined static int _get_baudrate(speed_t speed) ..\..\..\components\drivers\serial\serial.c(950): error: #20: identifier "TCIFLUSH" is undefined case TCIFLUSH: ..\..\..\components\drivers\serial\serial.c(951): error: #20: identifier "TCIOFLUSH" is undefined case TCIOFLUSH: ..\..\..\components\drivers\serial\serial.c(974): error: #20: identifier "TCOFLUSH" is undefined case TCOFLUSH: ..\..\..\components\drivers\serial\serial.c(910): warning: #177-D: function "_get_speed" was declared but never referenced static speed_t _get_speed(int baudrate) ..\..\..\components\drivers\serial\serial.c(923): warning: #177-D: function "_get_baudrate" was declared but never referenced static int _get_baudrate(speed_t speed) ..\..\..\components\drivers\serial\serial.c(936): warning: #177-D: function "_tc_flush" was declared but never referenced static void _tc_flush(struct rt_serial_device *serial, int queue) ..\..\..\components\drivers\serial\serial.c: 3 warnings, 19 errors ".\build\keil\Obj\rt-thread.axf" - 32 Error(s), 7 Warning(s). Target not created. Build Time Elapsed: 00:00:01 ``` - 定位编译不通过的问题,确认为libmodbus的头文件包含问题 - 工程配置:select ![2021-12-24_094908.png](https://oss-club.rt-thread.org/uploads/20211224/6b7484e7500bfdec89f2b96492cf5170.png) ![2021-12-24_094940.png](https://oss-club.rt-thread.org/uploads/20211224/0a79320c3e90a8be6d2d314224151b15.png) ## libmodbus软件包修改如下: - modbus.c 中:`#include
` -> `#include
` - modbus-rtu.c中:`#include
` -> `#include
` - modbus-private.h 中:增加`#include
` - 编译问题解决 ## 小结 - 可能最近内核规范化,修改了部分路径、头文件的包含需要更新 - 可以通过VS Code,全局搜索无法识别的函数、定义等,然后包含相应的头文件即可 - RT-Thread Studio的libmodbus软件包,编译不通过,可以参考上面的修改方法 ## 参考例程 [https://gitee.com/zhangsz0516/nucleo_l476rg_pm/tree/master/libmodbus_master](https://gitee.com/zhangsz0516/nucleo_l476rg_pm/tree/master/libmodbus_master)
3
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
张世争
学以致用
文章
131
回答
809
被采纳
175
关注TA
发私信
相关文章
1
RT-THREAD在STM32H747平台上移植lwip
2
正点原子miniSTM32开发板读写sdcard
3
反馈rtt串口驱动对低功耗串口lpuart1不兼容的问题
4
Keil MDK 移植 RT-Thread Nano
5
RT1061/1052 带 RTT + LWIP和LPSPI,有什么坑要注意吗?
6
RT thread HID 如何收发数据
7
求一份基于RTT系统封装好的STM32F1系列的FLASH操作程序
8
RT-Thread修改项目名称之后不能下载
9
rt-studio编译c++
10
有木有移植rt-thread(nano)到riscv 32位MCU上
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
UART
WIZnet_W5500
ota在线升级
freemodbus
PWM
flash
cubemx
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
中断
编译报错
Debug
SFUD
rt_mq_消息队列_msg_queue
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
a1012112796
10
个答案
1
次被采纳
踩姑娘的小蘑菇
4
个答案
1
次被采纳
红枫
4
个答案
1
次被采纳
张世争
4
个答案
1
次被采纳
Ryan_CW
4
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
YZRD
2
篇文章
5
次点赞
qq1078249029
2
篇文章
2
次点赞
xnosky
2
篇文章
1
次点赞
Woshizhapuren
1
篇文章
5
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部