Please read this well to make sure you understand what I want to do.
- I DO want Xcode to be able to compile, but only so I can debug in Xcode.
- I do NOT want to use Xcode to compile or upload the code to the Arduino board. I will use the Arduino IDE in "Use external editor" mode instead.
What I have done (also as a future reference for people who might want to do the same thing):
- In the project settings (click on the project file in the left pane)
- I have changed the compiler to GCC to avoid many errors.
I have added the following paths to the Header Search Paths and Library Search Paths:
- /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
(If you have installed Arduino.app somewhere other than the Applications folder, you will need to adjust the paths accordingly.)
In main.cpp, I have included <WProgram.h>
, but it wasn't enough. I was getting undefined identifier errors (for SPCR, SPE, MSTR, SPR1, SPR0) due to not being able to pass the -mmcu=somechipname
as a flag to the compiler, which caused no device to be defined and avr/io.h
to be unable to include the file that defined those symbols. I got around it by manually including <avr/iom328p.h>
which is the appropriate header file for my chip.
That's how far I got.
Now I get these errors:
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
The whole main.cpp including the evil offending code is this:
#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;
}
What do I about this?