英文:
Receiving SIGABRT on Raspi when trying to parse string to date with either std::get_time or strftime
问题
代码部分不翻译,以下是您提供的内容的翻译:
当我尝试使用std::get_time
或strftime
将字符串解析为日期时,在我的树莓派上会收到SIGABRT错误。但是当我在我的Ubuntu电脑上执行相同的代码时,它正常工作。
std::get_time
示例:
#include <chrono>
#include <iomanip>
#include <iostream>
int main() {
std::stringstream stream;
stream.str("09:35:44,02-23-2023");
std::tm tm{};
const std::string format = "%H:%M:%S,%m-%d-%Y";
if((stream >> std::get_time(&tm, format.c_str())).fail()) {
std::cout << "解析失败" << std::endl;
}
std::cout << std::chrono::seconds(std::mktime(&tm)).count() << std::endl;
}
我尝试在Buster和Bulleseye上的树莓派上执行代码,但都无法正常运行。而我的运行Ubuntu 22.04的计算机可以正常执行示例代码。我尝试查找在ARM架构上解析日期时的已知问题,但没有找到任何信息。
非常感谢任何帮助!
编辑: 我使用CLion的gcc工具链来编译程序,由cmake文件管理。我在两台树莓派上都尝试了远程编译(都是3b型号,一个运行Buster,一个运行Bulleseye),选择了来自bin目录的默认gcc和g++编译器(在Buster上是gcc-8.3.0,cmake 3.16,Bulleseye上是gcc-10.2.1,cmake 3.18.3)。我还尝试在Ubuntu上进行交叉编译(使用Ubuntu的arm-linux-gnueabihf-gcc/g++编译器),但如果我记得正确,那会出现不同的问题。我在CLion中使用远程gdb调试程序在树莓派上执行,而SIGABRT错误发生在调用std::get_time
期间。我甚至可以看到,检查tm
时,它包含正确的小时、分钟和秒,但然后似乎停止了。
再次感谢所有在这里发表评论和回答的人!
编辑2: 我将尽快尝试在全新设置的树莓派上编译和执行程序,只在树莓派上使用命令行,以排除与CLion工具链相关的任何问题。
编辑3: 再次感谢所有在这里提供意见的人。不幸的是,最不令人满意的解决方案起作用了。我今天再次尝试,但我无法再次复制错误,现在它可以正常工作。我只是无法弄清楚上周我做错了什么...对于给大家带来麻烦,我感到抱歉!
英文:
When I'm parsing a string to date with either std::get_time or strftime I receive a SIGABRT on my RaspberryPi. When I execute the same code on my Ubuntu computer it works fine.
std::get_time example:
#include <chrono>
#include <iomanip>
#include <iostream>
int main() {
std::stringstream stream;
stream.str("09:35:44,02-23-2023");
std::tm tm{};
const std::string format = "%H:%M:%S,%m-%d-%Y";
if((stream >> std::get_time(&tm, format.c_str())).fail()) {
std::cout << "Parsing failed" << std::endl;
}
std::cout << std::chrono::seconds(std::mktime(&tm)).count() << std::endl;
}
I tried Raspberrys with Buster and Bulleseye and both fail to execute the code.
My computer running Ubuntu 22.04 executes the example just fine.
I tried to find known issues when parsing dates on arm architecture, but did not find any.
Any help is greatly appreciated!
Edit:
I'm using CLion gcc-Toolchains to compile the program, managed by a cmake file.
I used remote compilation on either of the Raspberrys (both 3b, with either buster or bulleseye), selecting the default gcc and g++ compiler from the bin directory (on buster gcc-8.3.0, cmake 3.16 and bulleseye gcc-10.2.1, cmake 3.18.3). I also tried to crosscompile it on Ubuntu (with Ubuntus arm-linux-gnueabihf-gcc/g++ compilers), but that had different issues if I recall correctly.
I debugged the program in CLion with remote gdb executing it on the raspberry and the SIGABRT happens during the call to std::get_time. I can even see, inspecting tm, that it contains hour, minutes and seconds correctly, but then it seems to stop.
Thanks to everyone commenting and answering so far!
Edit2: I will try to compile and execute the program on a freshly setup Raspberry asap, command line only on the raspberry to rule out any issues with the CLion toolchain.
Edit3: Thanks again for everyone giving input here. Unfortunately the most unsatisfying solution worked. I tried it again today and I just cannot reproduce the error, but it is working now. I just can't figure out what I did wrong last week... Sorry for the hassle!
答案1
得分: 0
你的程序在运行最新的32位Raspberry PI OS上运行良好,可以在此处找到该系统的版本信息:
兼容性:
所有Raspberry Pi型号
Raspberry Pi OS桌面版
发布日期:2023年2月21日
系统:32位
内核版本:5.15
Debian版本:11(bullseye)
大小:924MB
显示SHA256文件完整性哈希:ff0ee221581d4f68257f2a78409a16660272a48d3e31b562a8d32a531a335ca2
lsb_release -a
没有LSB模块可用。
发布者ID:Raspbian
描述:Raspbian GNU / Linux 11(bullseye)
版本:11
代号:bullseye
uname -a
Linux raspberrypi 5.15.84-v7+ #1613 SMP Thu Jan 5 11:59:48 GMT 2023 armv7l GNU / Linux
g++ --version
g++(Raspbian 10.2.1-6 + rpi1)10.2.1 20210110
版权所有(C)2020 Free Software Foundation, Inc.
这是自由软件;请参阅有关复制条件的源代码。没有
保修;甚至不适合特定目的。
g++ -o 75547255 75547255.cpp
./75547255
1677144944
根据EpochConverter,1677144944是你想要转换的确切值:
GMT:2023年2月23日星期四上午9:35:44
您的时区:2023年2月23日星期四上午4:35:44 GMT-05:00
相对于15小时前
如评论中建议的,您需要提供有关硬件/操作系统/C++编译器的确切组合的详细信息,以便其他人可以尝试重现您所遇到的问题。
英文:
Your programs works fine on a RaspberryPi 3 running the latest 32 bit version of Raspberry PI OS available here:
<!-- language: lang-none -->
Compatible with:
All Raspberry Pi models
Raspberry Pi OS with desktop
Release date: February 21st 2023
System: 32-bit
Kernel version: 5.15
Debian version: 11 (bullseye)
Size: 924MB
Show SHA256 file integrity hash:ff0ee221581d4f68257f2a78409a16660272a48d3e31b562a8d32a531a335ca2
lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
uname -a
Linux raspberrypi 5.15.84-v7+ #1613 SMP Thu Jan 5 11:59:48 GMT 2023 armv7l GNU/Linux
g++ --version
g++ (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++ -o 75547255 75547255.cpp
./75547255
1677144944
1677144944 is, according to the EpochConverter, the exact value you wanted to convert:
<!-- language: lang-none -->
GMT: Thursday, February 23, 2023 9:35:44 AM
Your time zone: Thursday, February 23, 2023 4:35:44 AM GMT-05:00
Relative: 15 hours ago
As suggested in the comments, you would need to give the same level of details on the exact combination of hardware/operating system/c++ compiler you are using, so that others may attempt reproducing the issue you experimented.
答案2
得分: 0
我终于弄清楚了我做错了什么。
首先,我需要向所有查看我的示例的人道歉,因为这个示例完全正常工作。
我的问题是由于这个错误 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45896 导致的,这个错误在Ubuntu 22.04中已修复,但在Raspbian 11中没有修复。
现在我要么在解析之前修改字符串,要么寻找获取日期的不同方法,尽管第一种选项对我来说更有希望。
感谢大家帮助我!
英文:
I finally could figure out what I was doing wrong.
First of all I need to apologize to everyone looking at my example, because this is working absolutely fine.
My issue is occurring due to this bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45896 which is fixed in Ubuntu 22.04 but not Raspbian 11.
I will now either modify the string before parsing or look for a different way to get the date, although the first option seems more promising to me.
Thank you all for helping me with this!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论