我目前正在使用Kate和Arduino IDE为Arduinos开发一个库(实际上很少是Arduino特有的,但只是将示例从A-IDE上传到物理硬件很容易)。但是现在我已经达到了Kate使用起来相当繁琐的程度,所以我试图切换到CLion,问题是我无法使用linting和编译工作。我尝试使用Arduino plugin for CLion,它适用于小例子,但对我来说失败了,请记住Arduino IDE编译我的代码并上传它没有问题。
这是我的CMakeFiles.txt:
cmake_minimum_required(VERSION 2.8.4)
set(ARDUINO_SDK_PATH ${HOME}/arduino-1.8.2/)
set(PROJECT_NAME MyLibrary)
project(${PROJECT_NAME})
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake)
add_library(./modules/lib1/lib1.h)
add_library(./modules/lib2/lib2.h)
add_library(./modules/lib3/lib3.h)
add_library(./modules/lib4/lib4.h)
set(EXAMPLE2_SKETCH ./examples/example2/example2.ino)
set(EXAMPLE1_SKETCH ./examples/example1/example1.ino)
generate_arduino_firmware(EXAMPLE2_SKETCH)
generate_arduino_firmware(EXAMPLE1_SKETCH)
文件夹结构:
MyLibrary
├── drivers
│ └── HWLIB
│ ├── HWLIB.cpp
│ └── HWLIB.h
├── examples
│ ├── example1
│ │ └── example1.ino
│ └── example2
│ └── example2.ino
├── modules
│ ├── lib1
│ │ ├── lib1.cpp
│ │ └── lib1.h
│ ├── lib2
│ │ ├── lib2.cpp
│ │ └── lib2.h
│ ├── lib3
│ │ ├── lib3.cpp
│ │ └── lib3.h
│ └── lib4
│ ├── lib4.cpp
│ └── lib4.h
└── MyLibrary.h
1:在尝试刷新cmakefile之后,CMake几乎每一行都抱怨并且它没有任何意义:
CMake Warning (dev) at CMakeLists.txt:7 (add_library):
Policy CMP0037 is not set: Target names should not be reserved and should
match a validity pattern. Run "cmake --help-policy CMP0037" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
The target name "./modules/lib1/lib1.h" is reserved or not valid
for certain CMake features, such as generator expressions, and may result
in undefined behavior.
This warning is for project developers. Use -Wno-dev to suppress it.
You have called ADD_LIBRARY for library ./modules/lib1/lib1.h without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Warning (dev) at CMakeLists.txt:8 (add_library):
Policy CMP0037 is not set: Target names should not be reserved and should
match a validity pattern. Run "cmake --help-policy CMP0037" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
The target name "./modules/lib2/lib2.h" is reserved or
not valid for certain CMake features, such as generator expressions, and
may result in undefined behavior.
This warning is for project developers. Use -Wno-dev to suppress it.
You have called ADD_LIBRARY for library ./modules/lib2/lib2.h without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Warning (dev) at CMakeLists.txt:9 (add_library):
Policy CMP0037 is not set: Target names should not be reserved and should
match a validity pattern. Run "cmake --help-policy CMP0037" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
The target name "./modules/lib3/lib3.h" is reserved or not valid
for certain CMake features, such as generator expressions, and may result
in undefined behavior.
This warning is for project developers. Use -Wno-dev to suppress it.
You have called ADD_LIBRARY for library ./modules/lib3/lib3.h without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Warning (dev) at CMakeLists.txt:10 (add_library):
Policy CMP0037 is not set: Target names should not be reserved and should
match a validity pattern. Run "cmake --help-policy CMP0037" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
The target name "./modules/lib4/lib4.h" is reserved or not
valid for certain CMake features, such as generator expressions, and may
result in undefined behavior.
This warning is for project developers. Use -Wno-dev to suppress it.
You have called ADD_LIBRARY for library ./modules/lib4/TooSigning.h without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Generating NODE_SKETCH
CMake Error at cmake/Platform/Arduino.cmake:2130 (message):
ALL_SRCS not set: must define SRCS or SKETCH for target NODE_SKETCH
Call Stack (most recent call first):
cmake/Platform/Arduino.cmake:498 (required_variables)
CMakeLists.txt:22 (generate_arduino_firmware)
"您已为库./modules/lib3/lib3.h调用了ADD_LIBRARY,没有任何源文件。"但头文件指定源?
2:使用该CMakefile,CLion无法在modules文件夹中找到标准库和其他库。例如,当查看lib1.h时,我看到这些错误(标记为红色):
#include "modules/lib2/lib2.h"
^ Cannot find 'modules'
和
uint8_t variable = 0;
^ Can't resolve type 'uint8_t'
同样适用于Serial
,memmove
,malloc
等。
任何想法如何解决这些问题并使用适当的IDE来开发我的项目?
答案 0 :(得分:0)
由于MyLibrary.h
的设计令人怀疑,因此无法修复整个项目。但是对库尝试一下:
add_library(...)
替换所有include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules)
#include <lib1/lib1.n>