Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic 1 solution - 2 projects - 2 targets - shared source code (Read 3704 times)
Pascal Roobrouck
Junior Member
**
Offline


Posts: 19
Joined: Mar 3rd, 2017
1 solution - 2 projects - 2 targets - shared source code
Mar 3rd, 2017 at 7:13pm
Print Post  
Is it possible to have 
1 Visual Studio Solution
  and inside
2 Projects : 
* project 1 : a standard C++ Win Console Application, target for x86 
* project 2 : 'Arduino' project, target for embedded (Teensy 3.5 in my case)

Can I share source files in both projects, using some #define to include/exclude the platform specific stuff. (Ideally the build process sets the #define parameter..)

I am able to build for Windows and for Teensy but currently I need 2 'Visual Studio Solutions' for that, with duplication of the source code.. (and the hassle to keep them in sync)

Thanks!
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: 1 solution - 2 projects - 2 targets - shared source code
Reply #1 - Mar 3rd, 2017 at 8:54pm
Print Post  
Yes you have a lot of options. If you need to debug both projects at the same time then you will end up with two solutions but can still share code.

1)
When working with two or more projects in a solution the "Startup Project" becomes quite important. Visual Studio uses the Startup Project to make F5/Debug/Start work. 

note: If the Win32 project is the Sartup Project then when editing Arduino code the Visual Micro buttons and menu items will provide compile>upload for Arduino. If the arduino project is the Startup Project then the standard Visual Studio F5/Debug/Start will build and upload the Arduino project.

The Startup Project is shown with a bold name in the solution explorer. Right click to set a project as the Startup Project.

2)

Probably the best way to share code is to use Visual Studio C++ Shared Projects". Visual Studio will apply intellisense for the Startup Project when editing code in a Shared C++ Project. You will see that a shared c++ project is simply a .vcxitems project file instead of the usual .vcxproj project file. During a build, visual micro will copy shared project code files into a temp folder along with the project code files. The sub folder structure of a shared project will be reflected during copy. Therefore a shared project source in "proj\src\test" would be #included as "src\test" in the main project code.

Another way to share code is to click a project and select "Add existing item", then navigate to a folder with some cpp/h/c code and Visual Studio will add it to the project as a "Short cut/link". In this case, during a build, visual micro will build as if the linked code resides in the same folder as the arduino project code. Arduino builds happen in a temp folder, so linked sources are copied to the temp folder along with the project code prior to compile.

3)

If you switch on vmicro>compiler>verbose you will see the standard -D defines available to an arduino build. for example -dARDUINO= shows a define is available called ARDUINO. The micro controller family and type are also usually available as #defines. The #defines are specified in the build definition of whatever hardware you have installed so can change depending on hardware.

You can also add additional defines in the visual micro project properties http://www.visualmicro.com/page/User-Guide.aspx?doc=Project-Properties-Reference...

Visual Studio has it''s own defines which you will find for win32 apps. They will be different to arduino because it's using gcc (you prob know that)

this is a library shared project type because it has a library.properties. normal shared projects do not have a library.properties file and are compiled alongside the project code. library projects are compiled like arduino libraries.
« Last Edit: Mar 3rd, 2017 at 9:02pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline


Posts: 19
Joined: Mar 3rd, 2017
Re: 1 solution - 2 projects - 2 targets - shared source code
Reply #2 - Mar 3rd, 2017 at 10:37pm
Print Post  
Hi Tim, thanks for your excellent help.

1. no need to debug both at same time, so 1 solution should be ok. I also understand the concept of 'Startup Project'.

2. I tried to add source files using 'Add existing item' - 'Add as Link' but this 'Add as Link' selection is not available in my VS2015-Community.. I search the web, and it seems to be a frequent problem, which will probably be solved in VS2017... Undecided

Adding the files 'Add existing item' seems to work : I put the source files under the folder for the Windows project, and included them from this location into the ARM project. I think this works because for 'Arduino' builds all source files (no matter what location) are copied into a temp folder.

I'm still stuck with 1 thing : the ARM project yields a compilation error 'identifier uint32_t is undefined'. These safe int defines come from stdint.h, which shows correctly in the external dependencies. But when I look into this file, I see that most of it is excluded (through a #ifdef), probably because of some definitions somewhere else..

stdint.h is included in the same way in both Windows and ARM project. When compiling the windows project, it is included correctly, and the build succeeds.

When doing the ARM build, something else seems to get defined first, which then results in stdint.h to be skipped and resulting in a build fail.

Can it be something in the xxx.vsarduino.h ??
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: 1 solution - 2 projects - 2 targets - shared source code
Reply #3 - Mar 3rd, 2017 at 10:45pm
Print Post  
Hi,

The add as link is just confusion. Add existing files does add a link, it does not copy the source into the project but leaves it in place.

The vsarduino is ignored during arduino builds, it's just for vs intellisense.

I would expect that you have two projects, only the arduino project has a vsarduino.h created, the win32 project does not and does not have .ino files?

You might want to make a simple example and paste as a zip so I can see your config. It's difficult to understand how any arduino code will affect the win32 project.
  
Back to top
WWW  
IP Logged
 
Pascal Roobrouck
Junior Member
**
Offline


Posts: 19
Joined: Mar 3rd, 2017
Re: 1 solution - 2 projects - 2 targets - shared source code
Reply #4 - Mar 4th, 2017 at 11:52am
Print Post  
Hi Tim,

I think I took more than 1 step at a time, so I decided to rewind a bit..

1. I created two separate VS2015 'solutions', containing one project each : 
* a C++ Win32, created through 'File | New | Project'
* an Arduino/Teensy3.5, created through 'vMicro | New arduino Project' (I created a minimal blink-project to verify the complete build-upload was working)

2. I added some .cpp / .h class files from the Win32 project to the Arduino project through 'Add existing item'. They are stored in the folder of the Win32 project.

When I edit the shared source files , they are updated correctly, no matter from which solution I'm opening them.

It also simplifies things because platform-specific #define's can be put simply in the main.cpp (for Win32) and in the .ino file (for Arduino).

Thanks for your help   Smiley
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: 1 solution - 2 projects - 2 targets - shared source code
Reply #5 - Mar 4th, 2017 at 12:11pm
Print Post  
That's great. Thanks for the update.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint