openwrt 使用 clock_gettime 函数没有秒返回问题

本文介绍在OpenWRT环境下进行交叉编译的配置步骤,包括设置CMake的系统根目录、交叉编译器arm-gcc和arm-g++的路径,并针对编译过程中出现的特定问题提供了解决方案。

openwrt

编译器设置

set(CMAKE_SYSROOT /home/luke/openwrt/openwrt/staging_dir/target-mipsel_24kc_musl)

# 指定交叉编译器 arm-gcc 和 arm-g++
# 直接使用绝对路径
set(CMAKE_C_COMPILER /home/luke/openwrt/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.2.0_musl/bin/mipsel-openwrt-linux-gcc)
set(CMAKE_CXX_COMPILER /home/luke/openwrt/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-11.2.0_musl/bin/mipsel-openwrt-linux-g++)

现象:秒字段为空始终为0

ubuntu

同样的代码,使用gcc编译器,输出正常
在这里插入图片描述

解决办法
在这里插入图片描述

record.c:3265:48: error: passing argument 4 of 'strftime' from incompatible pointer type [-Werror=incompatible-pointer-types] 3265 | strftime(buffer, sizeof(buffer), "%H:%M:%S", &abstime); | ^~~~~~~~ | | | struct timespec * In file included from /home/tp/Project/NVMP/platform/nvmp/staging_dir/target-arm-openwrt-linux-uclibcgnueabi-sx25v2/usr/include/nvmp_common.h:13, from /home/tp/Project/NVMP/platform/nvmp/staging_dir/target-arm-openwrt-linux-uclibcgnueabi-sx25v2/usr/include/dms_common.h:19, from /home/tp/Project/NVMP/platform/nvmp/staging_dir/target-arm-openwrt-linux-uclibcgnueabi-sx25v2/usr/include/libdms.h:19, from record.c:25: /home/tp/Project/NVMP/platform/sdk/soc/ssc30x/uclibc-toolchain/arm-sigmastar-linux-uclibcgnueabihf-9.1.0/arm-sigmastar-linux-uclibcgnueabihf/sysroot/usr/include/time.h:200:32: note: expected 'const struct tm * restrict' but argument is of type 'struct timespec *' 200 | const struct tm *__restrict __tp) __THROW; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ cc1: all warnings being treated as errors Makefile:65: recipe for target 'record.o' failed make[4]: *** [record.o] Error 1 make[4]: Leaving directory '/home/tp/Project/NVMP/platform/nvmp/build_dir/target-arm-openwrt-linux-uclibcgnueabi-sx25v2/avts/storage' Makefile:70: recipe for target 'storage' failed make[3]: *** [storage] Error 2 struct timespec abstime; clock_gettime(CLOCK_MONOTONIC, &abstime); int milliseconds = abstime.tv_nsec / 1000000; char buffer[80]; strftime(buffer, sizeof(buffer), "%H:%M:%S", &abstime); fprintf(fp_time, "abstime: %s.%03d\n", buffer, milliseconds);
最新发布
11-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值