Develop and compile with Xcode 4

I'm trying to compile something for the Arduino using Xcode and the includes are a real nightmare. Especially the avr part. I don't exactly know what to include and whatever I tried, the compiler either didn't find it, either it couldn't even get to the end of it because of the amount of errors : "fatal error: too many errors emitted, stopping now" Heh.

I don't even want to use Xcode to upload code to the Arduino because from what I've read on the net and on the forum it seems like another nightmare. So I'll just use the Arduino IDE for that.

TL;DR : What to include and how? Because the compiler can't F$?&#%?&# find anything.

Thanks.

Because the compiler can't F$?&#%?&# find anything.

Which compiler? The XCode compiler can't find the avr or Arduino include files, but, so what? They are written in C or C++, which the XCode compiler can't deal with, anyway.

I'm trying to compile something for the Arduino using Xcode

The XCode compiler can't generate output for the avr chip, so this doesn't make sense.

Xcode uses CLang for C/C++/Obj-C/C++

The IDE and compiler cannot find the files.

Xcode uses CLang for C/C++/Obj-C/C++

Can CLang produce machine code for an avr chip? I doubt it.

Even if it can, you still plan to use the Arduino IDE to upload code to the Arduino. When you do that, it won't upload the machine code that XCode/CLang produced. It invokes the compiler/linker to generate new machine code that it uploads.

At best, you could use the XCode editor to edit the sketch, in which case, where the include files really are is not an issue.

I don't care about whether Xcode can produce machine code for the chip or not. I just want it to compile to see if it compiles. I don't want to have to switch to the Arduino IDE when I debug.

So, what files to include and how?

I got around to doing it somehow. It compliles but doesn't link, which is enough for what I want.
For future reference, here's what I've done :

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.

Hi!

Please have a look at the thread about makefile for Xcode.