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 Including External Files (Read 2848 times)
Groover75
Newbies
*
Offline


Posts: 3
Joined: Dec 11th, 2017
Including External Files
Dec 11th, 2017 at 3:52pm
Print Post  
I have an existing non-Arduino project with the following folder structure:

Top Level
  -> SharedCode
  -> SharedCode2
  -> PortForMicrocontrollerXXX
  -> PortForMicrocontrollerYYY
  -> PortForArduino

I am working in the 'PortForArduino' folder so this is where my VS2017 project file is. I need to include in the compile the shared code in the tree.

Because this is an existing project I can't make copies of the shared code or move it.

I don't care about compatibility with the Arduino IDE.

If I understand it right I can't create an Arduino library because I would have to put Arduino-specific files into the top level folder, which I can't do because no code resides there and it would break the folder hierarchy.

In the VM project properties under Extra Flags I have added:

Code
Select All
-I . -I ../SharedCode -I ../SharedCode2 



I understand this does not compile the code - fine.

I have added the shared code source files to the VS project.

In this post: http://www.visualmicro.com/forums/YaBB.pl?num=1455641592/16#16 and this one: http://www.visualmicro.com/forums/YaBB.pl?num=1455641592/14#14 you mention using shortcuts to bring in external code that is outside of the VS2017 project folder.

In VS2017 I right-click on my project, choose Add -> Existing Item... and choose a file but the Add button in the dialog does not have the drop-down option to add as a link. Seems that is only available for managed projects, e.g. .NET.

In one of the posts I referenced above you said:

Quote:
right click folder>add existing>link


Where is this - in Windows Explorer? VS2017?

The compilation error I get is:

Code
Select All
Fatal error: foo.h: No such file or directory 



foo.h is located in PortForArduino. It is included in a .c file in SharedCode.

Do you have any hints or suggestions for achieving what I want to do while respecting and maintaining my existing folder structure? Thanks!

« Last Edit: Dec 11th, 2017 at 4:57pm by Groover75 »  
Back to top
 
IP Logged
 
Groover75
Newbies
*
Offline


Posts: 3
Joined: Dec 11th, 2017
Re: Including External Files
Reply #1 - Dec 11th, 2017 at 4:41pm
Print Post  
OK, made some progress. It seems my relative paths were not working. If I use:

Code
Select All
-I "C:\foo\bar\baz\PortForArduino" -I "C:\foo\bar\baz\SharedCode" -I "C:\foo\bar\baz\SharedCode2" 



it compiles my external files and finds the header files.

Is there an equivalent in VM to VS's $(ProjectDir)?
« Last Edit: Dec 11th, 2017 at 4:58pm by Groover75 »  
Back to top
 
IP Logged
 
Groover75
Newbies
*
Offline


Posts: 3
Joined: Dec 11th, 2017
Re: Including External Files
Reply #2 - Dec 12th, 2017 at 3:30pm
Print Post  
After much searching I worked it out. I needed:

Code
Select All
-I "{build.project_path}" -I "{build.project_path}\..\SharedCode" -I "{build.project_path}\..\SharedCode2" 


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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Including External Files
Reply #3 - Dec 12th, 2017 at 3:47pm
Print Post  
Sorry for the delayed response. Yes that will work as long as there are no code files to be compiled. Just headers.

An alternative is to use visual studio shared projects. You can get the idea of how they work using the "add Library" menu which has a checkbox that "always creates project when adding libraries". Check the menu item then add spi, for example.


You will see that visual studio shared projects are simply a project_name.vcxitems file that appears as a special type of project in the solution tree. You can then right click "References" on one of the real arduino projects and then on the "shared projects" tab add the reference.

Only real projects can be "Start up Projects" which can be selected by right clicking a project in the solution tree. When editing shared project code Visual studio will automatically show intellisense based on the current startup project. So you can edit shared code for different platforms more easily.

A compiler -I include path is automatically added for each shared project root path (which is where the .vcxitems is located. Shared code must exist in or below the root folder. 

The top of the visual micro home page contains a few useful links such as cross-platform shared code and library development



note there is a shared code project entry in the File>New>Project list
« Last Edit: Dec 12th, 2017 at 3:55pm by Tim@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint