Adding "libraries" (Atmel studios 7)

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

Hello, i am quiet new to atmel studios and have experienced some problems when it comes to adding "libraries" (just .c and .h files), and after quiet a bit of research i'v atleast started to understand.

Afther my experience i therefore wanted to make a descussion that might help other beginners.

 

I found that there is several ways of making it possible to include the files(telling atmel studios where it should look for the files).

1: Using the toolchain: Simply adding the path to ther drerctories (AVR/GNU XXX compiler --> derectories) the including the files at the topp of your main.

2: Adding the .c files to the Solution Explorer(right click on your project and select add).

3: Edeting the makefile, but this way simply look to hard for a newbie(also what i found to be the case in other discussions).

 

My problem at the moment is that the .h and .c keeps confusing me. I realize that the .c is the defenition(the code) while the .h is the decleartion but the including process confuces me.

The case is that i have several files to add, some i .c and .h couples while i also have som seperate .h files.

 

Is it so that by including the .c file the couple would be good because the .c would itself include the .h file, while the rest of my .h files would have to be included seperately?

I keep seeing that people get told to add only the .c files while i also keep seeing code with included .h files.

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

This should be easy:

 

1) you add any .c you want as part of the compilation to the Solution/Project Exlporer

 

2) if the .h are not in a place that will be found "automatically" then in the project config ("Directories") you list any additional directories that the preprocessor should search in when trying to find the .h files

 

3) Err...

 

4) ... that's it.

 

There is a (1a) and that is that if you simply use [Add] to add .c files to the project they will be copied to the project directory. If you plan to use the same uart.c (say) in multiple projects you may actually prefer to keep just one central copy that all other projects can "see" (but don't copy locally). In this case before you click [Add] you click the drop arrow to the right of the button and instead use "Add as link". Now AS7 will not copy the file but just inserts a link to it in the project so that when it is compiled it reads in the file from the central source. You probably keep the associated .h files "close by" in that case so for (2) one of the Directories you add will be the place where the .c and .h live.

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

Hi, 

 

I have installed the complete prepackaged Windows version of the toolchain for AVR libc from  i dont think i am using them right due to getting a error when complying of "no such file or directory". and am wondering if some one would help me find the issue.

 

do i need to add any files to my project in "solution explorer"? or should including them at the to of my program be enough ?

 

After installing AVR libc i can see that the directory have been added to my toolchain library path.

 

this is how i am including them in my program 

 

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <Custom/Uart/UART-V1.h>
#include <avr/include/util/twi.h>

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

Tried to post a reply to the above but the FUBAR forum s/w messed up the include directives. Full story is that I tried to do this from the pad where the code editor does not work so my attempted reply was plaintext.

Sorry for the static.
Someone else will probably help you eventually.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Sat. Jun 17, 2017 - 06:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For one thing use <> for system includes and "" for your own headers.

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

The adding of the .c and .h pare shold be fine now.

 

Closing question lets say i have a single .h file simply for macros (there is no corresponding .c), should i include these seperatly because they are not necessary included elsewhere?

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

The rule with h file is simple. You include one because something it provides is used in the code that follows whether that be a macro, enum, typedef or function interface etc.

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

Alrigth, thanks for taking the time :)

 

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

thank you for the information it helped a lot