目录
1 gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized
2 error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘Eigen::internal::Packet4c’
3 error: comparison is always true due to limited range of data type [-Werror=type-limits]
4 loop_test.cc:561:23: error: ‘sleep_for’ is not a member of ‘std::this_thread’
最开始我是用的低版本的gcc编译的onnxruntime,按照下面博客的方式编译的。ubuntu交叉编译(armv7_32位)onnx源码_cpu版本_onnxruntime交叉编译_陈 洪 伟的博客-CSDN博客后来某项目中用11.3.1版本的aarch64-linux-gnu-g++再次编译时出现了很多错误,记录一下。
1 gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized
在某一次用gcc11再次重新编译这个onnxruntime的时候报下面的错误
gtest-death-test.cc:1301:24: error: ‘dummy’ may be used uninitialized
google搜索得到:Fix warning maybe-uninitialized by Thomas-Barbier-1A · Pull Request #3024 · google/googletest · GitHub
其实就是把警告当错误了,代码改一下初始化就没事了。
2 error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘Eigen::internal::Packet4c’
又出现了如下错误
/data/chw/onnxruntime_master/cmake/external/eigen/unsupported/Eigen/CXX11/../../../Eigen/src/Core/arch/NEON/PacketMath.h:1678:9: error: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘Eigen::internal::Packet4c’ {aka ‘struct Eigen::internal::eigen_packet_wrapper<int, 2>’} from an array of ‘const int8_t’ {aka ‘const signed char’} [-Werror=class-memaccess]
1678 | memcpy(&res, from, sizeof(Packet4c));
直接问Bing AI
-Werror=class-memaccess
是一个编译器选项,它将“类成员访问”警告视为错误。这意味着,如果您在编译C++代码时使用了这个选项,那么当编译器检测到您的代码中存在潜在的类成员访问问题时,它会报错并停止编译。类成员访问警告通常发生在使用
memcpy
或memset
等函数直接操作类对象内存时。这些函数可能会破坏类的封装性,并导致未定义行为。因此,使用-Werror=class-memaccess
选项可以帮助您检测并修复这些问题,以提高代码的安全性和可靠性。希望这些信息能够帮助您了解
-Werror=class-memaccess
选项的含义。如果您还有其他问题,请随时告诉我。😊
https://www.cnblogs.com/azureology/p/14891671.html
根据这篇文章,我在CMakeLists.txt里面增加下面的内容,该报错消失。
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=class-memaccess")
3 error: comparison is always true due to limited range of data type [-Werror=type-limits]
onnxruntime_master/cmake/external/json/single_include/nlohmann/json.hpp:8494:24: error: comparison is always true due to limited range of data type [-Werror=type-limits]
8494 | if ('\x00' <= c and c <= '\x1F')
直接问Bing AI
于是我在CMakeLists.txt里面增加如下内容
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=type-limits")
4 loop_test.cc:561:23: error: ‘sleep_for’ is not a member of ‘std::this_thread’
继续编译,又出现下面的报错,
onnxruntime_master/onnxruntime/test/providers/cpu/controlflow/loop_test.cc:561:23: error: ‘sleep_for’ is not a member of ‘std::this_thread’
561 | std::this_thread::sleep_for(std::chrono::seconds(3));
我在cmakelist里面增加如下内容
add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
添加上之后,还有报错,只是报错位置貌似变了,然后根据如下博客安装opencv4.4时出现错误 error: ‘sleep_for’ is not a member of ‘std::this_thread‘_安装open4.5时出现sleep_for(std::chrono::milliseconds{2}_changym5的博客-CSDN博客
我在loop_test.cc里面增加
#include <thread>
最后