Common source configured by .h files

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

Hi,

I have a set of files that perform common functions such as UART handling, queue templates and so one, which I would like to share between different projects.

 

My starting idea is to put those files in one folder, and then have the project specific files in another folder. so if one project wants a UART at 2400 bps, and an rx queue length of 100, I simply create the .h file to specify that, and then refer to (say ../common/uart.cpp).

 

However, if I set this up and then "add" the common files, studio copies them into my current folder. I end up with n copies of the common files. From a maintenance point of view, this is not what I want. I guess creating symbolic links to all of the common files might work but this would all be manual. Note that the common files will not compile without the required headers, so multiple project sin a single solution doesn't seem to work.

 

It seems to me that there should be a simple answer... but I haven't found it yet.

 

Any suggestions appreciated.

 

Thanks

Greg

regards
Greg

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

gregd99 wrote:
so multiple project sin a single solution doesn't seem to work.
Same code base, new chip - Add project to solution? | AVR Freaks

 

"Dare to be naïve." - Buckminster Fuller

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

The issue there seems to be that the common sources are in one project.... the controlling .h files are in another project.

 

That means that the common project can't compile.

regards
Greg

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

Are you talking about Studio 7? If so the "magic" is to use Add as Link rather than simple Add.

 

Another approach is to put the config options as -D's

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


Thanks for your suggestions.

 

clawson wrote:

Are you talking about Studio 7? If so the "magic" is to use Add as Link rather than simple Add.

I am using 7, however cannot find "add as link" - see below - "Add existing" takes me to a file browser, "Add as reference" takes me to a library list. Is there somewhere else to look?

 

 

clawson wrote:

Another approach is to put the config options as -D's

Yes.... but this is really messy, and unless I am missing something would end up with files for all projects in the one folder sad

 

Thanks

Greg

regards
Greg

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

gregd99 wrote:
so if one project wants a UART at 2400 bps, and an rx queue length of 100, I simply create the .h file to specify that, and then refer to (say ../common/uart.cpp).

Does "../common/uart.h" remain untouched ?

Perhaps a fleshed out skeleton minimal example would help.

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

There is is no ../common/uart.h. This file only exists in the project directory.

 

For example....

 

Common folder.

../common/uart.cpp

../common/project.cpp

../common/ etc etc

 

Project folder

main.cpp

uart.h

queue.h

etc

 

I would like to build a project in the project folder, which accesses the cpp files in the common folder, and configures with the .h data in the project folder.

 

Another potential problem is that the common .cpp files might want the .h files to be in the common folder.

 

All other suggestions are welcome. This seems like it should be a pretty common issue, with an obvious solution.

 

Greg

regards
Greg

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

So where does the template for uart.h come from ? Surely you wouldn't write the whole of it from scratch.

I'd expect it to be part of the source library, that;s why I asked about ../common/uart.h.

 

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


"Add as Link" is for .c (not .h) files and can be found here:

 

When you come to add some existing (and shared between projects) source file to your project you get to the file selector from "Existing Item..":

 

 

Instead of copy uart.c into your current project's folder (becoming the Nth copy of the same thing) it leaves the single one in its original location and the project just adds a link to where it is. When you later build the source that is compiled is that common one. If you later fix a bug in this uart.c (this example) then you change the common copy and all the projects that are sharing that one copy will see the change.

 

As for headers. You don't add those to the project but you do add search paths to them. So maybe something like:

 

 

I've created \common\drivers\uart\ directory in which to keep my uart.c (add as link) and uart.h and as a sub-dir from the current project I have created a .\config\ in which I will keep things like my uartbaud.h and whatever else.

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

Thanks very much for taking the time to spell all of that out.

 

A build has now run through. Next is to check that I don't have duplicated files etc and then see if the code actually runs! smiley

 

Thanks

Greg

regards
Greg