Go Down

Topic: Arduino on Xcode Project — Official Thread (Read 282461 times) previous topic - next topic


the "no .pde" problem is as easily solved by renaming your main file.

Easily solved by the typical XCode user.  I don't think you're properly visualizing the level of cluelessness of the would-be consumer of a pre-made Arduino sketch.  "rename main.cpp to foo.pde in a directory name foo, and put all the other file there too" just has SO many things that could go wrong.

On the other hand what is the benefit of working with pde files in XCode?

given a sketch containing .pde, .ino, .cpp, .c, and .S files, the .cpp, .c, and .S files are all compiled using standard c/c++/assembler conventions, while the .pde and .ino files are concatenated and (potentially)  get special preprocessing and automatic #includes.  Which is just a separate makefile rule, really, although the "preprocess" function doesn't exist.  While there's no big reason not to make .pde files have their own #includes and prototypes so that the preprocessing isn't needed in an XCode environment, excluding the processing of .pde/.ino files from your Xcode processing makes SW developed there "gratuitously incompatible" with the Arduino environment.

It is (I claim) desirable that the XCode Arduino developer be able to pack his Arduino project into a .zip file and ship it to an Arduino IDE user, where it should compile without any changes.  (I suppose that the zip file in question could be a separate XCode "target", but that seems to be unnecesarilly complicated.)


hmm there's some interesting stuff there...


Easily solved by the typical XCode user.  I don't think you're properly visualizing the level of cluelessness of the would-be consumer of a pre-made Arduino sketch.  "rename main.cpp to foo.pde in a directory name foo, and put all the other file there too" just has SO many things that could go wrong.

To me, it seems this point of view is a little bit overly cautious towards the "beginner Arduino User".
We were all beginners at a certain time and I think this little challenge of renaming a main.cpp file into a project_folder_name.pde file is only a small step to make you learn something new. Compared to learning about pointers, inheritance or even functions, renaming a file seems like a piece of cake. (mmm.. cake :-))

Before I started this effort to try to make an Arduino project with XCode, I had no knowledge at all about makefiles. Just by doing this I already learned so much about this completely new topic. It's fun! And it's a great way to learn too: trying to take this next step and looking through other people's code trying to make sense of it...
It's great that the Arduino IDE is working so good "out of the box" so beginners can get their hands dirty immediately. But at a certain point, if you want to create more complex programs you'll want to learn about classes, pointers, etc and then it is actually a good thing to have a more advanced software community that can happily program in their "professional" IDEs and assist those people.

But what if the Arduino IDE would allow correctly formatted C/C++ code? Then there would be no compatibility problem anymore, right?

I feel we're getting a little bit off topic here.. this thread was going to be about getting XCode to compile Arduino projects I believe.
So let's first get the templates ready for XCode 3.2.x and XCode 4.x and all the different boards, get them properly working for everybody and then worry about the potentially more complex problem of compatibility with the Arduino IDE.

If you have any suggestions on how to solve this problem, let's hear 'em! Maybe there is a very simple solution that I'm not seeing right now... like a simple text file included in the XCode template that explains what to modify for use in an Arduino IDE and vice versa?



Hi I've been playing around with this and can compile and upload sketches.  Could you explain exactly how I can include a user-defined library with this template?

Suppose I have a library named foo located in the standard places:


how can I include it in the Xcode project?

Also, is it necessary to have the "ArduinoProgram" class with setup() and loop() methods, or can I write setup() and loop() functions in main.cpp?

Thanks much


Nov 17, 2011, 11:57 am Last Edit: Nov 17, 2011, 11:59 am by timKnapen Reason: 1
Hi Professor,

That's a very good question. I suddenly realize that I've made this not so user friendly.
Basically, what you need to do is find the variables CPP_LIBRARIES, INCLUDE_LIBRARIES and CXXSRC and add some things.

I will update the github repository as soon as possible with a new makefile and build settings that allow you to add libraries of your own without needing to touch the makefile. I will report back here when that's uploaded to github.

Meanwhile, here is an example of how you could modify the makefile:
Make sure not to use ~/ for your home path, but the full name : /Users/yourUserName/ ... (because of a mistake I made)
Code: [Select]

#.. beginning of makefile...

# loading libraries
LIBRARIES = EEPROM Ethernet/utility SPI \
Firmata LiquidCrystal Matrix Sprite \
SD SD/utility Servo SoftwareSerial \
Stepper Wire Wire/utility

# Here you add the paths to the folders that contains the cpp files of your libraries:
OTHER_LIBRARIES = /Users/yourName/Documents/arduino_sketchbook/library1 \ # << backslash means "continue on next line"

# make the correct paths for the libraries
INCLUDE_LIBRARIES += $(addprefix -I,$(OTHER_LIBRARIES)) #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line

# find .cpp files in libraries
CPP_LIBRARIES = $(foreach lib,$(LIBRARIES),$(wildcard $(LIB_ROOT)/$(lib)/*.cpp))
CPP_LIBRARIES += $(foreach lib,$(OTHER_LIBRARIES),$(wildcard $(lib)/*.cpp))  #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line

# main file
TARGET = main

# find .c files in arduino directory
SRC = $(wildcard $(ARDUINO)/*.c)

# .cpp files from libraries and arduino directory
CXXSRC = $(wildcard $(ARDUINO)/*.cpp) $(CPP_LIBRARIES) $(SOURCES)
CXXSRC += $(wildcard $(OTHER_LIBRARIES)/*.cpp) #<<<<<<<<<<<<<<<<<<<<<<<<<<<< add this line

#.... rest of makefile...

You are right about ArduinoProgram, you don't really need it. It's only my preferred way of working.
Here's an example of main.cpp without the ArduinoProgram class:
Code: [Select]

#include "WProgram.h"

// Arduino doesn't know about new and delete, so let's teach 'm :
#include <stdlib.h> // for malloc and free
void* operator new(size_t size) { return malloc(size); }
void operator delete(void* ptr) { free(ptr); }
// from: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230935955

// you'll need to add function prototypes now...
void setup();
void loop();

// functions

void setup(){
Serial.println("this a test without ArduinoProgram");

void loop(){
Serial.println("we are looping...");

int main(void)
for (;;)
return 0;

I also have a question for you: What OS are you on and what board did you use to test?

Thanks for the feedback professor! Let me know if there is something else we can make better / easier to use...



Thanks Tim - I'll try this out this evening.

I an running Snow Leopard (10.6.8) and loading to a Duemilanove.



Things seem a more complicated with Xcode 4.2 running on Lion 10.7.2.

I had a look at Ino: maybe some ideas to grab?

I'm using 2 boards: Arduino UNO and chipKIT UNO32, with only one IDE Mpide 0022.


Hi Chaos & Avenue,

I have uploaded a new version of the XCode3.2 template to github. The adding of external libraries has been simplified a lot and it has (hopefully) clear instructions now in the README file. Get it here: https://github.com/timknapen/Arduino-With-XCode and let me know what you think :-)

I have also made a working XCode 4 project in Lion, but it seems that making templates is still a little too obscure. I haven't done too much research yet (just installed Lion today) so it might not be as hard as it looks.

At the moment, I think it might be better to not go for a project template, but do it the way openFrameworks does it: creating a blank project that has everything setup and just copy the whole project folder to start a new Arduino project in XCode 4

Thanks for the info Chaos, I will check the box on Duemilanove :-)

What are .ino files?



I've added a first version of an example XCode 4 project to the github repository.
Not a template, a blank project that you can copy and start from. When documentation on XCode 4 templates starts appearing I might have a go at it...

I'm not working in OSX Lion myself, so I'm going to wait for complaints/suggestions before I continue working on the XCode 4 project.



Very cool Tim - I followed the instructions in the new Readme and was able to compile a sketch with the Streaming and Flash libraries under Xcode 3.2.6!



Thanks Avenue,

I had checked that blog post, but it doesn't really give a lot more information than what you can find in the templates that Apple provides with XCode.

For now, I'm going to wait until there is decent documentation on XCode4 templates. There are just too many things that we'd have to find by trial&error...

But if anyone is up for the task, don't let my laziness stop you! :-)



Very cool Tim - I followed the instructions in the new Readme and was able to compile a sketch with the Streaming and Flash libraries under Xcode 3.2.6!


ah that's great news, I'm glad it's starting to become useable!



What we "need" is a command-line mode of the Arduino app that does the Arduino-style preprocessing on a set of .pde (or .ino) files.
Having to figure out exactly what it does (slightly differently) with each Arduino release is a pain, and makes implementing Arduino program builds in other IDEs an exercise in chasing not-fully-documented behaviors. :-(

I fully agree. Learning Makefile is just horrendous.

Another big benefit is to ensure consistency of the code between the Arduino IDE and alternative IDEs.

So a command-line mode of the Arduino app should be great!


I've just tried Tim's Xcode project on Xcode 4.2.1 running on Lion *.

Trying to compile it i get

Code: [Select]
make: *** No rule to make target `/Applications/Arduino.app/Contents/Resources/Java/hardware/Sanguino/cores/arduino/pins_arduino.o', needed by `bin/core.a'.  Stop.
Command make failed with exit code 2

Any ideas how to solve this issue?


* EDIT: I'm using UNO.

Go Up