Go Down

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

HaakonStorm

Wow! I just recently found the mpIDE app and the mpide xcode project, and wanted to try this with my UNO. I'm getting some strange
errors so far. I got as far as a clean compile, but uploader returns with error 2 (programmer not responding). I might be
doing something wrong.
This brach of the project (with mpide)  seems it has some traction,will be modding with this one some more testing.
Wish I had everything up and running already, to do some actual client/server programming ;)
Have a nice night, I'm going to bed zzz
/Storm

avenue33

#121
Feb 06, 2012, 08:18 am Last Edit: Feb 06, 2012, 09:16 am by avenue33 Reason: 1
The Index target throws a couple of errors but the most important is the index is built.



As a matter of facts, the errors are known bugs of Xcode.

The Index target is a trick: we declare a specific target for Xcode built-in LLVM 3.0 compiler. That way, we benefit from all the niceties of Xcode. Question: how to get them without this ghost target?

So we badly need some help from an Xcode 4 expert!

Visual Micro

not sure if this helps but in visual studio and arduino we copy all libs and code to a temp folder prior to compile. this is important because many user libs #include std libs (ie:../Wire/foo) so they all need to be located in the same directory system. without copy to temp, many arduino the sketches will never fully compile
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

avenue33

Thanks for the tip.

Building for Arduino or chipKIT works fine with no library related error. Actually, the error reported earlier is raised when Xcode built-in LLVM compiler is used as a target for all the code-sense.

Best solution would be to have code-sense working but without this ghost target.

Any Xcode specialist around willing to help us?

Hey guys,

Sorry for not responding for a while. I'm very busy at work right now. I will try to catch up in a week or so.

Avenue / olivier:
I'm not entirely sure, but I think XCode 4 won't do Code Sense without the fake target. I think XCode needs to be able to communicate with the compiler to do Code Sense. Because of the makefile, XCode can't really do this with the AVR-G++ compiler.
If there was a way to select AVR-G++ as a compiler in an XCode build process we could get this to work and we wouldn't even need the makefiles...
But if this would be possible, somebody would have discovered a long time ago and nobody would be messing with the makefiles in XCode.

best,
tim.

avenue33


not sure if this helps but in visual studio and arduino we copy all libs and code to a temp folder prior to compile. this is important because many user libs #include std libs (ie:../Wire/foo) so they all need to be located in the same directory system.

The makefile I use just does that: all .cpp .c .h files are converted into .o files which are stored under the Builds/ folder.

I'm not entirely sure, but I think XCode 4 won't do Code Sense without the fake target. I think XCode needs to be able to communicate with the compiler to do Code Sense. Because of the makefile, XCode can't really do this with the AVR-G++ compiler.

Nice to see you back :)

I've noticed the same behaviour on my MacBook.

If there was a way to select AVR-G++ as a compiler in an XCode build process we could get this to work and we wouldn't even need the makefiles...

We haven't explored yet the templates and frameworks and other advanced strings of Xcode 4. Maybe I'm expecting too much, but the solution may be there.

But if this would be possible, somebody would have discovered a long time ago and nobody would be messing with the makefiles in XCode.

Xcode seems exclusively devoted to OS and iOS app development.

What a pity :(

Visual Micro

Intellisense aside (i am sure you will get it working),

If xcode combines the pde/ino into a single cpp file, pulls in both core and user libs, compiles the lot without error that is very good. If it also returns clickable (goto source) errors for invalid source or lib files then I am very impressed! This had to be manually coded in the visual studio plugin, yes it works very well, seemlessly, but it's a chore to maintain.
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

avenue33

#127
Feb 06, 2012, 05:36 pm Last Edit: Feb 06, 2012, 05:39 pm by avenue33 Reason: 1
Intellisense aside (i am sure you will get it working),

I hope so ;) But help from an Xcode expert would be greatly appreciated!

If xcode combines the pde/ino into a single cpp file, pulls in both core and user libs, compiles the lot without error that is very good.

That's the standard feature from the makefile. It's neat and clean!

If it also returns clickable (goto source) errors for invalid source or lib files then I am very impressed! This had to be manually coded in the visual studio plugin, yes it works very well, seemlessly, but it's a chore to maintain.

The code check-as-you-go monitoring and click-to-error features only work when target = Index is activated, fooling Xcode.


More pictures are available here.

Visual Micro

Xcode is certainly better than I had assumed, that doesn't mean I will use it because I am a windows user and content with the visual studio solution. but for mac users it is a revelation, well done!

Quote
The code check-as-you-go monitoring and click-to-error features only work when target = Index is activated, fooling Xcode.


Yes, it is great to have some "intellisense/check as you go" error reporting. I also find it useful in Visual Studio but it seems that both xcode and vs are not using the gcc compilers for the intellisense. So many real exceptions don't appear until we compile. The errors returned by gcc are not very friendly and that's where the fiddly work began in the Visual Studio plugin development. Translating the gcc compiler outputs back to real file locations isn't much fun. If you find an easier solution than coding this manually then please let me know :)
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

avenue33

#129
Feb 07, 2012, 07:42 pm Last Edit: Feb 07, 2012, 07:44 pm by avenue33 Reason: 1
New Feb 08, 2012 release f brings
• Code-sense and click-to-error with standard targets
• Code check-as-you-type only with Index as target (continous compiling)





Please refer here for documentation and there for code.

Visual Micro

very VERY nice work. One little question.

Does this support multiple .pde/.ino files in a single project? If so, do any errors point back to the correct original source code lines?
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

avenue33


Does this support multiple .pde/.ino files in a single project? If so, do any errors point back to the correct original source code lines?

.pde / .ino files are considered as .cpp files and are natively supported.

However, some extra code is required and should be added:
Quote

// core library
#include "WProgram.h"

// needed here
// separate main.cpp creates conflicts
int main(void)
{
   init();
   setup();
   for ( ; ; ) loop();
   return 0;
}


Defining a separate main.cpp with main function or using the main.cpp provided by Arduino / chipKIT resulted in duplicate declarations and loss of code-sense.

Function main is the compulsory entry to the code to active code-sensing and all other niceties.

I haven't added yet a routine to check there's only one .pde / .ino file.

Xcode is poorly documented but has automatic features supposed to make developer's life easier. Xcode doesn't support plug-ins, so I'm afraid I can't go further... unless a white knight comes to the rescue!

Would you like to consider NetBeans instead? It's cross-platform and has an open architecture for plug-in. Combining your expertise with Visual Studio on Windows and my tests with Xcode on Mac OS X, we could do something really nice.

Visual Micro

Quote
pde / .ino files are considered as .cpp files and are natively supported.


That is probably a problem for many existing arduino sketch projects because the .pde files in arduino are joined into a single cpp file . This allows all of the variables and methods of every .pde to be shared (and is heavily used by many arduino sketches).

.cpp files need .h files and public declrations + #includes to be access by other files where as .pde files are global. Example: if we have void Test() {} in Blink2.pde then it should automatically be accessible from Blink1.pde

The joining of .pde files into a single .cpp is where the complexity arises when mapping error line numbers back to source. This is why I asked about it so often, it's messy!

Infact the problem is even worse, as you say you need the arduino.h or wprogram.h but Arduino also extracts and automatically adds the prototypes for each .pde method.
So when we translate error source line numbers we need to subtract the header lines then any other combined pde file line lengths.

Quote
Would you like to consider NetBeans instead

Normally no, because I am very happy with Visual Studio and would like to get back to building sketches instead of plugins :)
But my nephew wants me to install netbeans to help him make some minecraft mods :)
So maybe netbeans is a solution, escpecially because the arduino ide source is .java files so should be easily portable to netbeans? I would be happy to help you if you do!!
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

avenue33

I was talking about Xcode hidden features but you're right in pointing Arduino ones.

Wait a minute: Are they features or bugs?

IMHO, I think we shouldn't mimic Arduino bad habits --or not so good habits-- when using a real IDE as Visual Studio, Xcode, NetBeans or alike.

We could go back to a more canonical way of programming and get rid of the false automatons that make programers' life more difficult. 

That's the way I've taken, in order to get as much as possible from Xcode.

Quote
But my nephew wants me to install netbeans to help him make some minecraft mods 
Splendid, just suggest him this challenge: building an Arduino plug-in for NetBeans!

Visual Micro

Quote
IMHO, I think we shouldn't mimic Arduino bad habits --or not so good habits-- when using a real IDE as Visual Studio, Xcode, NetBeans or alike


I hear what you say but actually I think the Arduino design is for users who don't want the complexities of .cpp/.h and #includes. The objective with the Visual Studio plugin was to be 100% compatible with Arduino ensuring a 100% identical program output. That said, more advanced users should find your xcode solution to be excellent


Quote
Splendid, just suggest him this challenge: building an Arduino plug-in for NetBeans!


:) Can you believe it. 10 years old, already installed netbeans and has no interest in learning how to make an led light up with an Arduino. Doh!
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

Go Up