我正在尝试在 Arduino 上使用超 retrofit 伺服器。
我的草图中还没有任何实际代码,我只是想编译库。我遇到了很多错误。
在做了一些研究之后,我发现如果我将我的代码编译为 C 而不是 C++,我就不会得到这些错误。但我不知道该怎么做!
我正在使用适用于 Linux x64 的 Arduino 1.0。
@Omnifarious 我的 arduino sketch 中只有 #include 指令,此时是 sketch_jan20.cpp
我加了
#ifd __cplusplus{
extern "C"
#endif
这有助于消除以下错误,但其中一个错误除外: bool 值的重新定义。当我评论那一行时,我得到了一大堆新的错误。所有这些都是相同的,包括一些变体:
C:\Users\Ventrius\Programming\Arduino1.01\libraries\ArduinoApiC\/zoCommands.h:131: error: expected '=', ',', ';', 'asm' 或 ' __attribute__' 在 'zoCommandDoMove' 之前
错误:
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard -I/usr/share/arduino/libraries/ArduinoApiC /tmp/build3069866408398264713.tmp/sketch_jan20a.cpp -o/tmp/build3069866408398264713.tmp/sketch_jan20a.cpp.o
In file included from /usr/share/arduino/libraries/ArduinoApiC/zoSmsMaster.h:4:0,
from sketch_jan20a.cpp:1:
/usr/share/arduino/libraries/ArduinoApiC/zoTypes.h:39:18: error: redeclaration of C++ built-in type ‘bool’
In file included from /usr/share/arduino/libraries/ArduinoApiC/zoSmsMaster.h:5:0,
from sketch_jan20a.cpp:1:
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:19:29: error: non-local function ‘void zoErrorInit(volatile ZO_ERROR*)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:20:27: error: non-local function ‘u08 zoErrorGet(volatile ZO_ERROR*)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:21:44: error: non-local function ‘void zoErrorPut(volatile ZO_ERROR*, u08)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:22:32: error: non-local function ‘bool zoErrorIsEmpty(volatile ZO_ERROR*)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:24:30: error: non-local function ‘u08 zoErrorGetIsr(volatile ZO_ERROR*)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:25:47: error: non-local function ‘void zoErrorPutIsr(volatile ZO_ERROR*, u08)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
In file included from /usr/share/arduino/libraries/ArduinoApiC/zoSmsMaster.h:6:0,
from sketch_jan20a.cpp:1:
/usr/share/arduino/libraries/ArduinoApiC/zoProtocol.h:93:26: error: non-local function ‘bool zoProtocolCommandResponse(ZO_PROTOCOL_HAL*, ZO_PROTOCOL_PACKET*, volatile ZO_ERROR*)’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: error: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
In file included from sketch_jan20a.cpp:1:0:
/usr/share/arduino/libraries/ArduinoApiC/zoSmsMaster.h:55:18: warning: non-local variable ‘volatile ZO_ERROR* zoSmsMasterError’ uses anonymous type
/usr/share/arduino/libraries/ArduinoApiC/zoError.h:15:2: warning: ‘typedef volatile struct<anonymous> ZO_ERROR’ does not refer to the unqualified type, so it is not used for linkage
最佳答案
这个答案不是很有用,只是我试图解决这个问题的困惑性质。
将文件重命名为 .c
并使用 avr-gcc
编译它们,而不是 avr-g++
。
如果出现错误,则意味着您需要调整程序,甚至可能重写它以不使用任何 C++ 功能。
没有将 C++ 程序转换为 C 的通用公式。
另一种选择是创建一个您自己的 C 层供您的 C++ 代码调用。这层 C 代码将具有 C++ 友好的函数定义(即没有 bool
等),然后它将从 Arduino 库中调用非 C++ 友好的代码。
然后您可以创建包含 C 层函数定义的头文件,这些函数定义被包装在 extern "C"{
... }
中。确保这些头文件不包含您正在使用的 Arduino 库的任何头文件。
关于c++ - Arduino 编译为 C++,而不是 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441349/