How to import libraries into my project in Atmel Studio 7?

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI

 

I have seen a lot of information regarding this issue and still can't find an answer.

I am trying to create a project that will require a library that i ususally use in arduino IDE, that is SPI.h and MPU9250.h, that showl be simple: i open the project as C executable, i right click 'Libraries'->Add Library->Browse Libraries...go to the MPU9250 folder and select the .h and .ccp (not sure if i should import both). But when i try Build the project, i simply get: 

 

Severity Code Description Project File Line

Error MPU9250.h: No such file or directory GccApplication1 C:\Users\Luis\Desktop\GccApplication1\GccApplication1\main.cpp 9

 

error library

 

 

 

Anyone has an idea?

 

I have also searched for an alternative SPI library in Atmel Studio folder but can't find none =\

 

Thank you in advance.

 

Cheers, Luís Pereira.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it's Arduino libraries you want, I think the simplest way is to just create a simple Arduino sketch which uses the libraries in question, and then import that into AS.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Luís Pereira wrote:
i right click 'Libraries'->Add Library->Browse Libraries...
That menu entry is for using REAL libraries (ie an avr-ar created libXXX.a files). It is not the thing to use when you just have some .c/.cpp/.h files you want to add to a project because, guess what, that is not a "library". The term "library" has been bastardized over the years to now simply mean "any collection of support software". But AS7 uses "library" in the proper sense of the word. (a precompiled static library).

 

However, as Andy says, the way to do this is to import a sketch from Arduino. If you just start pulling in .cpp and .h you will have a nightmare job locating and importing all the dependencies. The sketch importer knows how to do that for you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all forthe answers. I have decided to go through the sketch way, and step by step withdraw what i need to do my stuff.

 

Cheers, Luís Pereira.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi yes but.. i was just thinking of doing the same thing for NeoPixel "library" in Arduino.

Problem is.. my Arduino board is a different CPU than my final hardware (SAMD21G on Arduino vs SAMD21E on my hw) and so even if I import the sketch I end up with all kinds of other problems which I am trying to fix.. so if you know of an easy way to import a sketch AND change cpu's let me know !  Thanks !

Mark

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In general, that's an entirely separate issue, called porting - ie, adapting code from one target to another.

 

But SAMD21G and SAMD21E are exactly the same CPU - just different pin counts and, possibly, memory sizes.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

 

I managed to solve the import libraries thing. It's been a while since i poisted this, but when some1 repplied to this and i noticed it hade nearly 2000 views, i thought i could leae here the response.

So basically just follown this explanation: https://www.youtube.com/watch?v=jP7rdSaZHJc

 

When you have your project opened, right click on the project name, on the right panel-> properties -> Toolchain -> Directories -> Add (here you just add the folders you want to invoke when including libraries)

 

You can eventually just have 2 folders (one for the .c files and one for the .h files), then by adding these folders to the directories that atmel search for libraries, you just do the include in brackets:

#include "Headers_example.h"

 

Pretty simple.

 

Cheers, Luís Pereira.

Last Edited: Thu. May 10, 2018 - 01:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

#include of .c files? Utter madness.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Absolutely!

 

surprise  no

 

Need a way to vote negative stars on that one!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are right, you dont have to include the c files. Bad example.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@awneil,  first.. nice cat...smiley

second yes.. porting is the right answer and SAMD21E is just smaller memory and fewer IO's / SECOMM's than SAMD21G,  so i think i will just trim the imported sketch down to size and "should just work" pretty much.

thanks

-mark

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

    I always thought that the first place a compiler is looking for included files is the project's folder itself. It looks like it is not the case for AVR Studio. Shouldn't be that way ?

 

    Years ago working with Visual FoxPro, in such cases it was looking in three places by default: the location the exe file was located, in \ProgramFiles\FoxPro, and Windows\System32. Only if none of these location would not suit your needs/preferences you would need to add new paths.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is nothing to do with Studio as such (unless it starts feeding in -I's). The GCC preprocessor's search rules are well documented in its manual.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

    Since both AS7 and the preprocessor omit the project directory path, it must be a reason for that. I am just curios what would be that reason since other software sees a benefit in having it.

 

    And as a side question, is there a way to make AS7 to add that -I option every time (no matter there is something useful in there or not) it invokes the compiler (to avoid manually adding that path on each project) ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

angelu wrote:
And as a side question, is there a way to make AS7 to add that -I option every time
Yeah, in the Project Properties is a section (under "GCC") called "Directories". Anything listed there is passed as -I