当前位置: 首页 > 工具软件 > Enable Copy > 使用案例 >

调试记录- error: #error “must enable c++17“

霍永年
2023-12-01
/opt/petalinux/2021.1/sysroots/cortexa72-cortexa53-xilinx-linux/usr/include/xir/util/any.hpp:28:2: error: #error "must enable c++17"
   28 | #error "must enable c++17"
      |  ^~~~~

定位到目标文件

/*
 * Copyright 2019 Xilinx Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once
#if __has_include(<any>)  && __cplusplus > 201700
#include <any>
#if !__cpp_lib_any > 0
#error "must enable -std=c++17 to use std::any"
#endif
namespace xir {
using any = std::any;
namespace stdx = ::std;
}  // namespace xir
#else
#error "must enable c++17"
#endif

解决方法:
原因是写的CMakeLists.txt文件没有添加对C++17的支持,所以在工程目录下的CMakeLists.txt中添加以下语句:

SET( CMAKE_CXX_FLAGS "-std=c++17 -O3")

其中,参数CMAKE_CXX_FLAGS含义是: set compiler for c++ language
而后面的-O3(是字母opq的o,大写的欧)是用来调节编译时的优化程度的,最高为-O3,最低为-O0(即不做优化)

 类似资料: