Sar*_*pps 13 c++ arduino arduino-ide
我正在为Arduino IDE的特定板创建一个库.图书馆工作得很好,现在我退后一步来添加OO.该库是.c和.cpp文件的混合.我知道为了添加类,我只需要使用.cpp.
这是LED.h文件.
https://gist.github.com/SaraJo/182220fda82cbe30255fe95f59d4a6b4
这是LED.cpp文件.
https://gist.github.com/SaraJo/1b3d6967d7bc2ef2e70d79025b755eb9
我得到的错误是:
In file included from /Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/Arduino.h:54:0,
from /Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/ble-nrf51822-master/source/main.c:49:
/Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/LED.h:12:1: error: unknown type name 'class'
class LED {
^
/Users/sarachipps/Library/Arduino15/packages/Jewelbots/hardware/nRF51822/1.0.0/cores/JWB_nRF51822/LED.h:12:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class LED {
^
exit status 1
Error compiling for board JWB nRF51822(V1.0 32KB).
Run Code Online (Sandbox Code Playgroud)
我猜Arduino将.cpp文件视为.c,是否需要设置编译器标志?谢谢.
所以,问题是C编译器main.c
不理解C++头文件中的"class"关键字LED.h
.你能不能改main.c
到main.cpp
,看看是否可行?
(您可能还需要添加
#ifdef __cplusplus
extern "C" {
#endif
Run Code Online (Sandbox Code Playgroud)
在顶部,和
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)
在main.h
文件的底部(或者可能是main.cpp
文件?),这样C++就不会试图破坏你的某些函数的名称,以便链接器可以找到它们......
归档时间: |
|
查看次数: |
885 次 |
最近记录: |