我正在尝试使用 esp-idf 构建一个项目,我的文件使用
-Wpedantic
,但我在框架文件中遇到一些错误。
这是我的项目结构:
.
├── CMakeLists.txt
├── main
│ ├── CMakeLists.txt
│ └── main.cpp
./CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(my-project)
./main/CMakeLists.txt:
idf_component_register(SRCS "main.cpp"
INCLUDE_DIRS "."
PRIV_REQUIRES "lwip")
set(MY_FLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"-Werror"
"-Werror=unused-function"
"-Werror=unused-variable"
"-Werror=unused-but-set-variable"
"-Werror=deprecated-declarations"
)
target_compile_options(${COMPONENT_LIB} PRIVATE ${MY_FLAGS})
./main/main.cpp:
#include "esp_log.h"
#include "lwip/sockets.h"
const char *TAG = "wifi_manager";
extern "C" void app_main() {
ESP_LOGI(TAG, "Hello world");
}
当我编译项目时,出现以下错误:
In file included from /home/adrian/repos/stack-overflow-example/main/main.cpp:2:
/home/adrian/repos/esp-idf/components/lwip/include/lwip/sockets.h:8:2: error: #include_next is a GCC extension [-Werror]
8 | #include_next "lwip/sockets.h"
| ^~~~~~~~~~~~
In file included from /home/adrian/repos/esp-idf/components/lwip/port/esp32xx/include/arch/cc.h:12,
from /home/adrian/repos/esp-idf/components/lwip/lwip/src/include/lwip/arch.h:48,
from /home/adrian/repos/esp-idf/components/lwip/lwip/src/include/lwip/debug.h:40,
from /home/adrian/repos/esp-idf/components/lwip/lwip/src/include/lwip/opt.h:52,
from /home/adrian/repos/esp-idf/components/lwip/lwip/src/include/lwip/sockets.h:42,
from /home/adrian/repos/esp-idf/components/lwip/include/lwip/sockets.h:8:
/home/adrian/repos/esp-idf/components/newlib/platform_include/errno.h:10:2: error: #include_next is a GCC extension [-Werror]
10 | #include_next "errno.h"
| ^~~~~~~~~~~~
cc1plus: all warnings being treated as errors
我的期望是
-Wpedantic
标志仅适用于我的文件,所以我不会收到这些错误
不幸的是,您在 CMakeLists.txt 中无能为力。当客户端中使用
-Wpedantic
时,ESP-IDF 供应商似乎不会尝试链接他们的项目。这个 cmake function 应该由他们修复,或者你可以在你的目录中本地修改它:
macro(__component_add_include_dirs lib dirs type)
foreach(dir ${dirs})
get_filename_component(_dir ${dir} ABSOLUTE BASE_DIR
${CMAKE_CURRENT_LIST_DIR})
if(NOT IS_DIRECTORY ${_dir})
message(FATAL_ERROR "Include directory '${_dir}' is not a directory.")
endif()
- target_include_directories(${lib} ${type} ${_dir})
+ target_include_directories(${lib} SYSTEM ${type} ${_dir})
endforeach()
endmacro()