我目前使用Kate和Arduino IDE开发Arduinos库(实际上很少有Arduino特定的内容,但是从A-IDE上传示例到物理硬件很容易)。但现在我发现使用Kate相当麻烦,所以我尝试切换到CLion,但问题是我无法在其中启用linting和编译。我尝试使用CLion的Arduino插件,它对于小的示例代码有点作用,但是对我来说不起作用,请注意,Arduino IDE没有问题编译我的代码并将其上传。
这是我的CMakeFiles.txt:
同样适用于
你有什么想法可以解决这些问题并使用合适的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)
您已经调用了ADD_LIBRARY命令去创建库文件"./modules/lib3/lib3.h",但是没有指定源文件?
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来开发项目吗?
.c
和.h
文件。如果这些源文件是用于库的,那么这些库是否已经被构建了呢?也就是说,是否已经有了.a
或.lib
文件,或者.dll
文件? - ryyker.a
或.lib
,我可以假设那些预编译的库文件只有在处理动态链接库时才是必需的,而在静态链接时像Arduino IDE/avr-gcc一样则不需要吗? - Avamanderadd_library
的第一个参数是目标名称,而不是文件。但是其余的参数应该是源文件。像这样:add_library(lib1.h ./modules/lib1/lib1.cpp)
。无法找到头文件的问题可以通过常规的include_directories或target_include_directories
来解决。顺便说一下,在几乎任何CMake手册中都有关于库的创建描述。我建议在继续之前先阅读它。 - Tsyvarev