Go Down

Topic: How does the Arduino build system work? (Read 2412 times) previous topic - next topic

stdio_h

I'm working with AVR microcontrollers in Atmel Studio and I'd like to put some code in a "library" directory to be able to include this code in my future projects. I would like to #include <some_module.h> in my projects and let the compiler/linker do they work with no extra compilation flags. In GCC there's no easy way of doing this, but Arduino does exactly this. We put some .cpp and .h files in a library directory once, and from that moment on we can just #include <some_module.h> and every thing goes right.

What magic does Arduino do? Can anyone help me with this?

Robin2

#1
Feb 18, 2017, 10:16 am Last Edit: Feb 18, 2017, 10:17 am by Robin2
I always thought the #include <some_module.h> was a standard part of C right from the beginning.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

stdio_h

We can #include <some_module.h>, using <> if some_module is part of a precompiled library placed in specific directories. Also, I think there's some flags that should be used in the compilation and linking process.

But what I want is to #include <some_module.h>, just like Arduino does, with non precompiled library files, and without user extra configuration at compile time.

Robin2

#3
Feb 18, 2017, 12:25 pm Last Edit: Feb 18, 2017, 12:27 pm by Robin2
That seems to be a question that should be asked on an Atmel Studio Forum. Us Arduino users don't have a problem so how would we know to fix it?   :)

If you turn on the verbose messages in the Arduino preferences you can see all the flags etc that are used in the compile process.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

stdio_h

Why should I ask about how Arduino works on an Atmel Studio Forum?

westfw

Quote
What magic does Arduino do?
Arduino has a standard structure and place for "libraries", filesystem and naming-wise.   So when you say "#include <NAME.h>" in your source code, the IDE parses that before the compile, and adds "-I/lots/of/file/path/stuff/NAME/src/NAME.h" to the compile command, and it copies "/lots/of/file/path/stuff/NAME/src/NAME.cpp" along with possibly other stuff (/lots/of/file/path/stuff/NAME/utility/*.c", etc) to the build directory so that it can be compiled along with your sketch.

It's a lot like using ASF Explorer in Atmel Studio.   You've tell the IDE that you want to use a particular feature, and it goes and gathers the various bits and either puts them where you need them, or figures out where they are and adds that info into the build.  AS uses the project files to hold the info, Arduino manages to sneak it into the source file (by being restrictive about name/library mapping/etc.)

stdio_h

#6
Feb 18, 2017, 01:49 pm Last Edit: Feb 18, 2017, 02:19 pm by stdio_h
Thanks, westfw. Very useful answer. You put me on the tracks.

Could you please link some documentation, libraries, or any other resource that you think can help me learning more about that (the Arduino thing, not ASF)? Since Arduino Software is GPL and LGPL, I'm thinking about use it in a project I'm working on, but I really don't know where to start.

Thanks, again.

pert

I'm not sure exactly what you're asking for but this is the repository for the tool that does the Arduino IDE's include magic (as well as other things):
https://github.com/arduino/arduino-builder

stdio_h

Yep! I think that repository have some good things for me. Thanks, pert.

Go Up