[TUT] Adding source and header files efficiently in Studio

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

Instead of copying source and self-written header files to a multi-file Studio project, there's a better way. Instructions apply to Studio 4.18, SP2. Create a folder for header files that you've written and a second folder for reusable C source code modules. Mine are "My_Includes" and "My_LIBs". Put all header files you've written in one and whatever reusable source modules in the other.

For Header Files:

1) Hit the "Edit current configuration options" button ( the white gear icon opposite-right to the "build" button ).

a) OR do: Project-> "configuration options"

2) Hit "include Directories" button and then the yellow folder near the upper right hand corner, then a browse box will open and you'll see 3 "..." Hit those and navigate to WHEREVER your include folder is and hit "ok" ( Of course you can add subdirectory folders ).

For source files:

Do the same with the "Libraries" button just below the "Include Directories" button for your source files. Such source files won't show up in your project folder, but that's ok.
---------------------------------------------------

Now with a new project open, you have to add whichever files are needed.

For Source Files:

In the project tree, right click the yellow "source files" and do "add existing source file(s)".

For Header Files:

Do the same steps with the "Header Files", in the project tree. You must also use #include "some_header_file" in each project C source file where it's needed. See abcminiuser's tutorial Modularizing C Code: Managing large projects if you don't understand my last sentence.

You don't have to add header files to that folder in the tree, but if you don't then the header files will appear in the "external dependencies" folder automatically. I like to see them in their own folder, apart from the system file "clutter" of the external d. folder.
----------------------------------------------------

Now in your project files you can just do, for example:

#include    

OR

#include  "spi.h"

etc. for all header files you've written and will use. For your C modules, just navigate to your LIBs folder in the project view and add them.

Advantages:

1) You don't have to hassle with navigate -> copy -> pasting them to the current project folder any more !

2) If you modify your modules / header files while still developing said files, then when you save the changes they apply to the master file and you're done. Much better than saving the project copy and STILL having to jump through hoops to have to save those changes to the master through a copy -> navigate to master-> paste ( "overwrite" it ). It especially saves time if you're modifying multiple module / header files ( just hit "save all" ) !

I used Studio for years to do multi-file projects the "hard" way and I thought I was stuck with it ( since I never bothered to read the entire Studio manual to learn about the 2 options mentioned above ). So for any 'freaks that stumble onto this before you find out via Studio's help file ( I got the idea that the Studio IDE MIGHT be able to do these things from a project book that used the MPLAB IDE :roll: ), this tut's for YOU ! :wink:

Jerome

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Fri. Jul 8, 2016 - 01:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was puzzled as to why AS5 wouldn't allow me to include delay.h even though found in toolchain. This solved the puzzle. 8)

In Studio 5, you can open the project's properties either from toolbar menu Project (screenshot 1) or from Project Explorer window by right click on your project name (screenshot 2). Once in the properties page, go to GNU C Linker -> Libraries, then click on the "+" icon in Library search path. This brings up a file browser, select the path you want the linker to search (screenshot 3), and click "OK" all the way back. You can add more paths from all drives and network places.

After this, instead of writing an awkward

#include "../../../../../../Program Files (x86)/Atmel/AVR Studio 5.0/AVR Toolchain/avr/include/util/delay.h"

I simply do

#include 

In fact, when I start to type "

Attachment(s): 

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

This isn't a tutorial - it sounds more like a bug report.

(and why is that everyone else using toolchain/AS5 can just use just as they have always done in AS4? Sounds like the problem may be local to your own installation)

I'll move this to the AS5 forum where the developers can see/comment on this.

Moderator

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

Clawson, my post is clearly a tutorial, I don't know why you moved it !? :? Espespcially when I don't reference AS5 at all ( I'm glad my tutorial :wink: helped valleyman , though. ) It seems like another bug in AS5 ( what's new... ), I agree with you on that. I need you to move it back where it belongs ( actually both, since it helped valleyman... I need ma props, dude 8) ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Apologies - thread now back where it belongs - it was valleyman's post I was responding too - not sure how I missed your post previously :oops:

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

Clawson wrote:
...it was valleyman's post I was responding too - not sure how I missed your post previously
That's what I thought had happened. :wink:

Valleyman, I suggest posting a link in AS5 forum to your post here or some indicator in that forum of this bug in AS5 ( it could as Clawson, suggested in your overall setup, though ).

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

indianajones11 wrote:
Valleyman, I suggest posting a link in AS5 forum to your post here or some indicator in that forum of this bug in AS5 ( it could as Clawson, suggested in your overall setup, though ).

Though my unfortunate example may have revealed a bug, I intended to illustrate that the same technique demonstrated in this tutorial can apply in AS5 as well. (I used all defaults from fresh AS 5, project created with AS5 template. If relative path util/ is expected to work from ASF without explicit linker directive, it's got to be a tool chain bug.)

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

Can you explain how this would be done in Studio 6.1? I cannot find the configurations options. I am copying the Header file with no success.
Thanks

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

jstockma wrote:
Can you explain how this would be done in Studio 6.1? I cannot find the configurations options. I am copying the Header file with no success.
Thanks
I don't use Studio 6, so I wouldn't know. Ask over in the Studio 6 forum and someone will help you.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Hello AVRfreaks,

I modified the SD Arduino library and I want to include this to my current project

I've tried to follow the steps and this is the result:

The header files show up in the "External dependencies" folder

During the linking process he cannot find the files apparently

I'm using AVR Studio 4 because I have a cheap programmer which doesn't work with newer versions.

Thanks in advance and Merry Christmas to you guys :wink:

Attachment(s): 

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

It is not enough to only include the header files. You will also need to add the corresponding C/C++ source files to the project so that they get compiled (they will NOT get compiled merely because you've #included the header files).

Quote:
During the linking process he cannot find the files apparently

It is not the (.h) header files that the linker can not find. It is the (.o) object files that comes from compiling the C/C++ source files. Since you've not added the source files to the project they are not compiled, and because of that there are no such object files for the linker to consume, and so the linker must protest with an error.

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"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]

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

Quote:
2) Hit "include Directories" button and navigate to YOUR include folder and hit "ok" ( Of course you can add subdirectory folders ). Do the same with the "Libraries" button just below the "...Directories" button for your source files.

By "include directories" I added the "SD" directory and the "SD/Utility" directory. By "libraries" I first added both the directories and used "add object" to add all of my files one for one.

Did I made a mistake here? thanks in advance :)

Attachment(s): 

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

I haven't checked my emails in awhile...

Merry CHRISTmas !

Yes, you made mistakes. Remove everything you added using "add objects". Hit the "Libraries" button and then the yellow folder near the upper right hand corner, then a browse box will open and you'll see 3 "...". Hit those and navigate to WHEREVER your C source files are and select that folder ( Do the same for the header files. ). Finally, to add source files to a pjt., in the project tree, right click "source files" and do "add existing source file(s)". This way, you don't need to copy the file from that dir. and then paste it into a project folder. You could do the same for header files and they'll show up in the header file folder on the tree, or just leave as it is and they show under "external ..."

I've added a bit more detail to the tut. for how to navigate to the source/header files.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

I have the same problem,how do i add .h files and .c files to winavr programmer's notepad?

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

Wrong place to ask that question. (a) this is a tutorial so only posts should be feedback about post #1 and (b) your question has nothing to do with this tutorial anyway.

 

So this is locked. (anyone with real feedback to add contact a moderator to unlock this).

 

(oh and by the way this is 2016 not 2006 - no one uses Programmers Notepad as an IDE for WinAVR these days!)

Topic locked