问题

Ubuntu 18.04升级至20.04后系统自带gcc也由7.5升级至9.3出现兼容性问题
原先可以编译的c++工程如今报错

error: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of a non-trivial type ... leaves 94 bytes unchanged [-Werror=class-memaccess]

解决

g++高版本检查更加严格,确定程序没有问题
通过向CMakeLists.txt中传入-Wno-error=class-memaccess参数抑制错误
例如

# Set C/CXX compiler flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-error=deprecated-declarations -fstack-protector-strong -Wno-error=strict-aliasing -Wno-error=class-memaccess")
set(CMAKE_CXX_STANDARD 11)

参考

gcc8 compiler error: class-memaccess · Issue #2931 - GitHub

相关文章:

  • 2021-07-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-10-28
  • 2021-08-19
猜你喜欢
  • 2021-07-21
  • 2021-07-01
  • 2022-12-23
  • 2021-07-18
  • 2021-10-16
  • 2021-12-30
  • 2021-09-16
相关资源
相似解决方案