3

我正在尝试在 Arduino 上使用 Supermodified 伺服。

我的草图中还没有任何实际代码,我只是想编译库。我有很多错误。

在做了一些研究之后,我发现如果我将我的代码编译为 C 而不是 C++,我不会得到这些错误。但我不知道该怎么做!

我正在为 Linux x64 使用 Arduino 1.0。

@Omnifarious我的arduino草图中只有#include指令,此时是sketch_jan20.cpp

我添加了

#ifd __cplusplus{
extern "C"
#endif

这有助于消除以下错误,除了其中一个错误:布尔值的重新定义。当我评论那条线时,我得到了一大堆新的错误。它们都是相同的,包括以下一些变化:

C:\Users\Ventrius\Programming\Arduino1.01\libraries\ArduinoApiC\/zoCommands.h:131: error: expected '=', ',', ';', 'asm' or '__attribute__' before '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
4

1 回答 1

2

这个答案不是很有用,只是我试图处理这个问题令人困惑的性质。

将文件重命名为.c并用于avr-gcc编译它们,而不是avr-g++.

如果您遇到错误,这意味着您需要调整您的程序,甚至可能重新编写它以不使用任何 C++ 功能。

没有将 C++ 程序翻译成 C 的通用公式。

另一种选择是创建自己的 C 层供 C++ 代码调用。这层 C 代码将具有 C++ 友好的函数定义(即 nobool等),然后它将从 Arduino 库中调用非 C++ 友好的代码。

然后,您可以创建包含 C 层函数定义的头文件,这些函数定义包含在extern "C" {...中}。确保这些头文件不包含您正在使用的 Arduino 库的任何头文件。

于 2013-01-21T15:06:13.883 回答