Hi, today we will talk about precompilation of Arduino libraries in Atmel Studio 6 and how to use precompiled libraries in your projects. You should create and cofigure new project, add required files, compile... and that's all! All steps was described in part 1. But I prepared for you quick action list which you could follow to create precompiled Arduino Servo library. When you will be familiar with steps, you could easily create projects for other libraries like Wire and SPI.
- Create new project: Ctrl+Shift+N or right click on solution -> Add -> New project..., select 'GCC C++ Static Library Project' and name it Arduino.Precompiled.Servo. Also in 'Solution:' drop down check that 'Add to solution' item selected.
- Remove files automatically added to project: select file Arduino.Precompiled.Servo.cpp in solution explorer and press Del or right click on file and select Remove. If asked, press "Delete" button to delete file permanently.
- Add required files to project - in our case add as links 2 files Servo.cpp and Servo.h from (SolutionDir)\arduino-1.0.3\libraries\Servo.
- Configure project - Build tab: press right click on project, select Properties, goto Build tab. Set "Artifact Name" to libarduinoservo for all build modes.
- Configure project - Build events: add post build event to copy resulting library to external folder. It is optional step, but sometimes useful...
xcopy "$(OutputDirectory)\$(OutputFileName)$(OutputFileExtension)" "$(SolutionDir)$(SolutionName).$(Configuration)\" /f /y
- Configure project - Toolchain - AVR\GNU C Compiler: as we have only cpp files in our project, we could skip configuration of AVR\GNU C Compiler.
- Configure project - Toolchain - AVR\GNU C++ Compiler - Symbols: (both build modes)
- Configure project - Toolchain - AVR\GNU C++ Compiler - Directories: (both build modes)
- Configure project - Toolchain - AVR\GNU C++ Compiler - Optimization:
- Release build mode: in Other flags textbox add text '-fdata-sections', and check Prepare functions for garbage collection
- Debug build mode: no changes
- Configure project - Toolchain - AVR\GNU C++ Compiler - Miscellaneous: in Other flags textbox add text '-fno-exceptions' in both build modes.
- Configure project - Toolchain - AVR\GNU Linker - Libraries: in this project we can skip it, but usually you should add name of used libraries to 'Libraries' section and path to folder where libraries located to 'Library search path' section. Name of the library should be added without 'lib' prefix like: arduinocore and not libarduinocore. Also do that in both build modes, or you could use different paths\libraries for different build modes.
- Configure project - Toolchain - AVR\GNU Linker - Optimization:
- Release build mode: check 'Garbage collect unused sections' and 'Relax Branches'
- Debug build modes: skip
- Also, sometimes you create projects that have dependencies on libraries produced by other project in same solution. In such case you should correctly setup dependencies to prevent situations when dependent project building before depending. To do this right click on project, select 'Project Dependencies...' and check required project(s), so Atmel Studio will have an ability to calculate correct build order.
Video below provides quick demo about how to use precompiled Arduino Wire library in Atmel Studio 6: