请仔细阅读本文以确保您了解我想要做什么。
- 我确实希望 Xcode 能够编译,但只有这样我才能在 Xcode 中进行调试。
- 我不想使用 Xcode 编译代码或将代码上传到 Arduino 开发板。我将在“使用外部编辑器”模式下使用 Arduino IDE。
我所做的(也可以作为将来可能想做同样事情的人的引用):
- 在项目设置中(单击左 Pane 中的项目文件)
- 我已将编译器更改为 GCC 以避免许多错误。
我已将以下路径添加到 header 搜索路径和库搜索路径:
- /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/lib/gcc/avr/4.3.2/include
- /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include
- /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino
(如果您已将 Arduino.app 安装在 Applications 文件夹以外的位置,则需要相应地调整路径。)
在 main.cpp 中,我包含了 <WProgram.h>
,但这还不够。由于无法通过 -mmcu=somechipname
,我遇到了未定义的标识符错误(针对 SPCR、SPE、MSTR、SPR1、SPR0)作为编译器的标志,这导致没有定义设备和 avr/io.h
无法包含定义这些符号的文件。我通过手动包含 <avr/iom328p.h>
来绕过它这是适合我的芯片的头文件。
这就是我得到的结果。
现在我得到这些错误:
Undefined symbols for architecture i386:
"_init", referenced from:
_main in main.o
"_setup", referenced from:
_main in main.o
"_loop", referenced from:
_main in main.o
"_pinMode", referenced from:
SBSetup() in main.o
"_digitalWrite", referenced from:
SBSetup() in main.o
包括恶意违规代码在内的整个 main.cpp 是这样的:
#include <WProgram.h>
#include <avr/iom328p.h> // Getting around warning "device type not defined"
#define NumLEDs 25
#define clockpin 13 // CI
#define enablepin 10 // EI
#define latchpin 9 // LI
#define datapin 11 // DI
int LEDChannels[NumLEDs][3] = {0};
int SB_CommandMode;
int SB_RedCommand;
int SB_GreenCommand;
int SB_BlueCommand;
void SBSetup(void) {
pinMode(datapin, OUTPUT);
pinMode(latchpin, OUTPUT);
pinMode(enablepin, OUTPUT);
pinMode(clockpin, OUTPUT);
SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0);
digitalWrite(latchpin, LOW);
digitalWrite(enablepin, LOW);
}
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
我该怎么办?
最佳答案
这两个很棒的引用让您设置 XCode 不仅可以编译,还可以上传:
- http://www.quietless.com/kitchen/setting-up-xcode-to-compile-upload-to-an-arduino-atmega328-duemilanove/
- https://github.com/timknapen/Arduino-With-XCode#readme
第一个解释了您需要的额外工具,第二个提供了 XCode 4.2(及之前版本)的项目模板。
我都用过,效果很好。
关于c++ - 为 Arduino 开发的 Xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7265870/