multiple projects that share the same source code

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

What's the best way to have multiple projects that share the same source code in AtmelStudio?

 

One might be a UC3 project the other might be Atmega project.

 

Idea is to easily maintain standard code that works for both architectures without having multiple copies of the code.

This topic has a solution.
Last Edited: Tue. May 29, 2018 - 11:09 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just the same as any other multiple project. Create subdirectories for src, project1, project2, ...
Target specific code is in projectN directory. Common code in src directory and used with "Add as link" . Search path for src.
.
The same approach can be used for IAR, Keil, AS7, .... specific stuff.
.
Note that AS7 attempts to create unmaintainable multiple source files at every opportunity.
Choose carefully.
.
David.

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

Thanks David,

 

Looks promising but for each source file I add as a link, when I compile I get "opening dependency file *.d No such file or directory"

Also "recipe for target *.o failed"

 

What's going on there?

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

Zip up your project directory and attach it to your message.
It is always wise to make clean first. This might solve your problem if there are stale files hanging around.
.
David.

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

I closed the project and reopened it and it shuffled folders around and stuff, its messed up I will try to start from scratch.

 

How do I deal with includes?

should I change my #includes to point to the actual file or should it work to the link still?

or should I be adding the new common directory in Properties Directories etc?

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

Zip up your project.    Then we can probably see where your problem is.

 

Alternatively,   start again.     Place the source files in the common src directory.

 

Then create each project.  Add common files as link.   Add specific files as copy.  

Edit project Properties for "All configurations".   Add src directory for includes.    Add any common library(s).

 

David.

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

I created a new project, when I close and reopen it the linked files move to a new location, Is this a bug?

 

Solution Explorer

 

Last Edited: Sun. May 27, 2018 - 10:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For headers just #include "foo.h" but if the location of foo.h is not immediately obvious use "Directories" to specify the directories to search which are then passed as -I

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

I use linked folders (in both Studio and Eclipse) without problem.

Some time ago I answered a question about this very behaviour.

 

https://www.avrfreaks.net/forum/studio-701188-works-miserably-me

 

 

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

Wow I don't get it, attached real basic zip, its messed up!

link files not where I wanted it, strange folders are being created and it doesn't compile.

Cant find common.h even though I have added all directory paths in project compiler properties.

 

Am I doing something wrong?

Attachment(s): 

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

My Studio isn't AVR32 enabled so had to re-enter your project. I'm using 7.0.1188

 

I did get it to work but had forgotten the work-rounds I needed to do.

 

Steps to Create:

  1. I created the folder CommonSrc {grey bar} as below.
  2. Into that folder I added common.cpp & common.h as links.
  3. Close and re-open the solution (the bug mentioned in the associated thread)
  4. Atmel Studio creates the circled (virtual) folders.
  5. Manually add the linked directory into the Includes directory list as in the screenshot; otherwise common.h cannot be found. (This is another bug in Studio)
  6. Optionally remove (and delete) the original CommonSrc created in step-1. (An exception is generated but the solution reloads fine)

 

 

 

My Project directory tree looks like this:

Z:\savman>tree /f
Folder PATH listing for volume VBOX_Public
Volume serial number is 00000200 0000:0811
Z:.
├───Test
│   └───UC3
│       │   UC3.atsln
│       │
│       └───UC3
│           │   UC3.cppproj
│           │   UC3.componentinfo.xml
│           │
│           ├───Debug
│           │   │   Makefile
│           │   │   makedep.mk
│           │   │
│           │   ├───UC3
│           │   │   └───CommonSrc
│           │   └───src
│           └───src
│                   main.cpp

└───Common
    └───src
            common.cpp
            common.h

 

Hopefully that helps explain the madness.

 

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

That's exactly what I found, I'm curious though doesn't adding the common directory to the compilers directory defeat the purpose in the linked files?

Correct me if I'm wrong but adding linked files allow you to only add some files from the common directory to your project?

So the compiler directory added should be to the link not the file. Otherwise the compiler will build all executables in the common directory even if not added as part of the project.

This would be a problem for me I think.

 

I also created a support case with Microchip, see what they come back with...

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

You are adding TWO different things:

 

1) source files

2) headers

 

They are added by different routes.

 

1) source files have to be listed in the project as inputs to the build. You don't want them copied so you "add as link". That just means that as the IDE goes down the list of things to be built it doesn't look in local directories but at the target location of the link.

 

2) header files are quite different. It's up to you the programmer how you handle this. In the limit you could hard code the entire path to "distant" headers in the #include so something like #include "e:\mylibs\avr\uart\uart.h" but putting paths in source makes it very hard to relocate it later. You actually want to just be able to use #include "uart.h" but to do that the compiler has to know that to find this it should look in e:\mylibs\avr\uart. So to do that you tell it separately using -I on the command line so in this case -I "e:\mylibs\avr\uart"

 

A lot of folks seem to be under the misapprehension that the paths to the sources and the paths to the headers should be given the same way. While you can also, in the Solution Explorer, add the headers to the project too. That is ONLY so you can gain double-click editing access easily. It is not used in any way to advise the compiler where the headers are located.

 

(and in all the above when I say "compiler" I really mean "pre-processor" - it is the pre-processor that needs to know where header #inlcude targets are because #inlcude is a pre-processor command).

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

What you see in the Solution Explorer is the logical view.    Not the actual layout on disk.     However the default will mimic the disk layout unless you specify otherwise.

 

You can create whatever logical structure you want.   And add files to whichever node that you want.

 

At the end of the day,   a file in your logical structure gets compiled.    It must be able to locate any header files that it needs.    AS7 tends to work with a single global set of Properties.    Other IDEs have global properties and you can add extra local properties to individual files or nodes e.g. SYMBOLs or additional INCLUDE paths.

 

AS7 only lets you turn compilation on or off for an individual file.   

 

David.

Last Edited: Tue. May 29, 2018 - 08:55 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, so digesting that, you are saying I can add the common (file)directory to the compilers list of directories so the compiler can find the headers when required.

 

I'm still un-clear on exactly how I list source files in the project as inputs to the build. I get the link thing i.e. not having to make copies of files.

Does the IDE look for source files in the logical view down the branches of the tree starting from the project?

So when it finds a link in the project to a source file it will build it.

Any source files in the common path(At the trunk, outside the project) that were not linked in the project do not get built?

 

Cool, I see the property to stop compiling a source file, useful to know!

Last Edited: Tue. May 29, 2018 - 09:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can't remember exactly how AS7 does it but in general the XML of the project file for Visual Studio has things like:

  <ItemGroup>
    <ClCompile Include="..\..\..\..\..\..\legacy\src\algo\XYZ_example\company_XYZ_plugin\company_dllmain.cpp" />
    <ClCompile Include="..\..\..\..\..\..\legacy\src\algo\XYZ_example\company_XYZ_plugin\company_XYZ_drawing.cpp" />
    <ClCompile Include="..\..\..\..\..\..\legacy\src\algo\XYZ_example\company_XYZ_plugin\company_XYZ_plugin.cpp" />
    <ClCompile Include="..\..\..\..\..\..\legacy\src\algo\XYZ_example\company_XYZ_plugin\stdafx.cpp" />
  </ItemGroup>

So whatever you do in the GUI, ultimately the PROJ file just records a whole bunch of <clcompile> relative paths to the sources to be built. If you want to know more about this simply open and study an AS7 project file to see what it has actually recorded there.

 

The IDE as actually pretty dumb - anything that is added to the project tree that has a .c or .cpp extension will be built. Only if the properties are set to "exclude from build" will it not be considered. Right click a file to see the option to exclude it.

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

Thanks guys,

 

That's really helpful! Think I get it, sounds like it will work, will have a play

 

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

I got feedback from Microchip, It is not normal for the links to move, This is a known bug and it has been fixed. However, the fix will be available as part of next Atmel Studio release.