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 Problem including files in Shared Code Projects (Read 2079 times)
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Problem including files in Shared Code Projects
Apr 19th, 2019 at 2:14am
Print Post  
Hi,
I continue to have trouble with shared code.  I have a main job (call it sketch1)that is self-contained apart from Arduino libraries.  I have two other subsidiary jobs (sketch2 and sketch3) that interface via One Wire to sketch1, so naturally a lot of the data structures and so on are common.  I got the solution for sketch2 to work satisfactorily using a shared code project (SCP1) containing items from sketch1.  sketch3 is very similar to sketch2, and I am attempting to set up its solution by adding SCP1, plus another (SCP2) that includes items from sketch2.  I hope that's clear.

What I am seeing seems odd to me.  I will attach part of the compiler output illustrating my issue.

There is a file (base_UICLass.cpp) created for sketch2 that #includes base_UICLass.h.  This header file #includes  UI_structs.h from sketch1, which is contained in SCP1.  So far, so good, sketch2 builds fine.  For sketch3's solution, I added SCP1 to the solution and created another project SCP2 which contains base_UICLass.cpp and base_UICLass.h.

When VS/VM is compiling a sketch3 file (Sem_main.cpp), it finds both base_UICLass.h and  and UI_structs.h in SCP1 just fine (as did sketch2); when it compiles base_UICLass.cpp from SCP2, it finds base_UICLass.h, but not UI_structs.h.

I notice that the compiler command lines place Sem_main.cpp in the VMbuilds folder, but base_UICLass.cpp is placed in the Arduino sketchbook folder; this seems to be the only difference, and no doubt explains the above behaviour.  From my reading, this looks wrong.  I quote from the web page:
".... To share code just as if it has been added directly to the project as opposed to using a seperate library.
....
#include linked code as if it exists in the project folder (without path qualifier).
....
Note: When the project is compiled any linked sources are copied into the hidden build folder along with the other project sources."

My question is why, in this case, is base_UICLass.cpp not compiled out of the build folder?  (It is copied there, I noticed.)  Any thoughts about why this did not happen here?  I have noticed a tendency for VS projects to get muddled, requiring deletion and redefinition, but I have tried that without success.

I noticed that SCP1 has only .h files, no .cpp files.  As a test, I added a file Test.cpp to SCP1, which #includes UI_structs.h.  This compiled fine in sketch2, where the compiler command line looks for Test.cpp in the VMBuilds folder.  However, when I compiled sketch3 with this changed SCP1, the compiler command line now looks in the sketch2 sketchbook folder (which is where it is), not the VMBuilds folder, and it now cannot find  UI_structs.h.  So this looks like that is my problem.  But I still don't know why or how to fix it.

Thanks for your support,
Jed
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem including files in Shared Code Projects
Reply #1 - Apr 19th, 2019 at 12:20pm
Print Post  
Hi,

Please zip and email the solution containing the projects with link to this thread.

Thanks

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem including files in Shared Code Projects
Reply #2 - Apr 19th, 2019 at 2:38pm
Print Post  
Thanks for sending the files. There isn't only one solution (sln) in the file and it shows a lot more projects than you zip contained so it is difficult to easily see what you are doing.

The files you sent also show some confusion with locations of sources which might confuse things. 

The files show three attempted projects. 2 x arduino sketch projects which look good and also a folder called SmrtHeads which I guess should be a shared project but it is not.

The project file of SrchLightHead shows links to a variety of shared projects (either code of libraries) but the locations are not great and also the physical files are not provided in your zip.

I suggest we step back a little and clean up the code folder structure. That will also make things simpler and more obvious for you. Keep in mind that an arduino sketch project is a final application, the code can not also be a shared project. There are ways so share code between application projects but is will confuse even more.

An important note is that the visual studio .sln, .vcxproj and .vcxitems files are simple text files that contain paths to the files and shared projects you have referenced. You can edit them with a text editor if need be.

1)

You SrchLightHead project shows you have configured many shared project references. Please clear the list down and exclude all standard arduino libraries from your project and solution. (I have changed the paths slightly to protect names)

Code
Select All
<ImportGroup Label="Shared">
    <Import Project="..\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.vcxitems" Label="Shared" />
    <Import tems" Label="Shared" />
    <Import 21\libraries\EEPROM\EEPROM.vcxitems" Label="Shared" />
    <Import Project="..\libraries\onewirearduinoslave\onewirearduinoslave.vcxitems" Label="Shared" />
    <Import Project="..\libraries\OneWire-master\OneWire-master.vcxitems" Label="Shared" />
    <Import " Label="Shared" />
    <Import Project="..\libraries\SerialPort\SerialPort.vcxitems" Label="Shared" />
    <Import Project="..\SmrtHeads\SharedCode\SharedCode.vcxitems" Label="Shared" />
    <Import Project="..\SmrtHeads\SharedCodeRS\SharedCodeRS.vcxitems" Label="Shared" />
  </ImportGroup>
 



2)

Do NOT put libraries or code below the _micro-api folder of a project. This facility is an older way of working with shared external code and libraries prior to the release of support for shared projects (vcxitems). Shared projects allows us to organize code in a cleaner way. See the next point

3)

I recommend creating a folder for the .sln file at the root of any "projects" structure and then create more obvious places to locate arduino sketch code versus shared code.

For example this folder structure:-

Code
Select All
MyProjects
 MyProjects\MyProjects.sln

 MyProjects\SharedCode

 MyProjects\SharedCode\Project1
 MyProjects\SharedCode\Project1\Project1.vcxitems
 MyProjects\SharedCode\Project1\foo.h
 MyProjects\SharedCode\Project1\foo.cpp

 MyProjects\SharedCode\Project2
 MyProjects\SharedCode\Project2\Project2.vcxitems
 MyProjects\SharedCode\Project2\foo.h
 MyProjects\SharedCode\Project2\foo.cpp

 MyProjects\SharedLibraries

 MyProjects\SharedLibraries\SharedLib1
 MyProjects\SharedLibraries\SharedLib1\SharedLib1.vcxitems
 MyProjects\SharedLibraries\SharedLib1\library.properties
 MyProjects\SharedLibraries\SharedLib1\foo.h
 MyProjects\SharedLibraries\SharedLib1\foo.cpp

 MyProjects\Projects

 MyProjects\Projects\Project1
 MyProjects\Projects\Project1\Project1.vcproj
 MyProjects\Projects\Project1\Project1.ino

 MyProjects\Projects\Project2
 MyProjects\Projects\Project2\Project2.vcproj
 MyProjects\Projects\Project2\Project2.ino 







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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem including files in Shared Code Projects
Reply #3 - Apr 19th, 2019 at 2:39pm
Print Post  
Thanks for sending the files. There isn't only one solution (sln) in the file and it shows a lot more projects than you zip contained so it is difficult to easily see what you are doing.

The files you sent also show some confusion with locations of sources which might confuse things. 

The files show three attempted projects. 2 x arduino sketch projects which look good and also a folder called SmrtHeads which I guess should be a shared project but it is not.

The project file of SrchLightHead shows links to a variety of shared projects (either code of libraries) but the locations are not great and also the physical files are not provided in your zip.

I suggest we step back a little and clean up the code folder structure. That will also make things simpler and more obvious for you. Keep in mind that an arduino sketch project is a final application, the code can not also be a shared project. There are ways so share code between application projects but is will confuse even more.

An important note is that the visual studio .sln, .vcxproj and .vcxitems files are simple text files that contain paths to the files and shared projects you have referenced. You can edit them with a text editor if need be.

1)

You SrchLightHead project shows you have configured many shared project references. Please clear the list down and exclude all standard arduino libraries from your project and solution. (I have changed the paths slightly to protect names)

Code
Select All
<ImportGroup Label="Shared">
    <Import Project="..\libraries\Adafruit_NeoPixel\Adafruit_NeoPixel.vcxitems" Label="Shared" />
    <Import tems" Label="Shared" />
    <Import Project="C:\Users\[your ROM\EEPROM.vcxitems" Label="Shared" />
    <Import Project="..\libraries\onewirearduinoslave\onewirearduinoslave.vcxitems" Label="Shared" />
    <Import Project="..\libraries\OneWire-master\OneWire-master.vcxitems" Label="Shared" />
    <Import " Label="Shared" />
    <Import Project="..\libraries\SerialPort\SerialPort.vcxitems" Label="Shared" />
    <Import Project="..\SmrtHeads\SharedCode\SharedCode.vcxitems" Label="Shared" />
    <Import Project="..\SmrtHeads\SharedCodeRS\SharedCodeRS.vcxitems" Label="Shared" />
  </ImportGroup>
 



2)

Do NOT put libraries or code below the _micro-api folder of a project. This facility is an older way of working with shared external code and libraries prior to the release of support for shared projects (vcxitems). Shared projects allows us to organize code in a cleaner way. See the next point

3)

I recommend creating a folder for the .sln file at the root of any "projects" structure and then create more obvious places to locate arduino sketch code versus shared code.

For example this folder structure:-

Code
Select All
MyProjects
 MyProjects\MyProjects.sln

 MyProjects\SharedCode

 MyProjects\SharedCode\Project1
 MyProjects\SharedCode\Project1\Project1.vcxitems
 MyProjects\SharedCode\Project1\foo.h
 MyProjects\SharedCode\Project1\foo.cpp

 MyProjects\SharedCode\Project2
 MyProjects\SharedCode\Project2\Project2.vcxitems
 MyProjects\SharedCode\Project2\foo.h
 MyProjects\SharedCode\Project2\foo.cpp

 MyProjects\SharedLibraries

 MyProjects\SharedLibraries\SharedLib1
 MyProjects\SharedLibraries\SharedLib1\SharedLib1.vcxitems
 MyProjects\SharedLibraries\SharedLib1\library.properties
 MyProjects\SharedLibraries\SharedLib1\foo.h
 MyProjects\SharedLibraries\SharedLib1\foo.cpp

 MyProjects\Projects

 MyProjects\Projects\Project1
 MyProjects\Projects\Project1\Project1.vcxproj
 MyProjects\Projects\Project1\Project1.ino

 MyProjects\Projects\Project2
 MyProjects\Projects\Project2\Project2.vcxproj
 MyProjects\Projects\Project2\Project2.ino 







« Last Edit: Apr 19th, 2019 at 2:40pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Re: Problem including files in Shared Code Projects
Reply #4 - Apr 21st, 2019 at 2:57pm
Print Post  
Tim,
Thanks for the response.  I was a little skeptical that your suggestion to move files around would help, as the whole point is to allow code to be located "anywhere".  Further, I found the problem also occurred with just one main project and two shared code projects. But I tried your scheme, except the files for the second shared project were left in a different Arduino sketchbook folder rather than with the .vcxitems file.  The only significant different from my layout was that the location of the two projects' unique files.

However, it does work that way.  I also learned that Arduino allows .ino file to be in subfolders of the Sketchbook/<sketch> folder, which I did not know.

So thank you for the help, though I'm still mystified why the original problem occurred; put it down to a Visual Studio vagary?

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


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Problem including files in Shared Code Projects
Reply #5 - Apr 21st, 2019 at 3:07pm
Print Post  
Good to hear it's working but because I didn't see a real solution it's difficult to be 100% accurate with my answer. However I think there a few factors that were at play:-

  • Yes it's possible to have sub folders below a sketch however that should be the [sketch]\src and folders below the src folder.
  • Use of "other projects" in folders below a sketch is liable to cause some confusion due to use of the build folder for the actual build.
  • Use of the [sketch]\_micro-api\libraries should be avoided for multiple reasons such as you expect shared code not library compile and the fact that since the release of shared projects there is no need to have projects in known locations below some other project.
  • Arduino does not really have such as thing as a project so it involves scanning the files in and below a sketch to find sources. Therefore it's easy to bump into files that don't belong to the project. It's generally better to keep arduino projects clean.


Generally there was a lot of room for confusion with your layout however I can see that it was born from a mixture of older documentation and examples. We are working on a new documentation system and will explain this area of more advanced development more clearly.

Finally you will find that source control works much better with your new structure. With the solution in the top folder and all other projects defined clearly in their own folders it will be easy for a source control tool to check-in and manage the changes.


« Last Edit: Apr 21st, 2019 at 3:13pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
NF1Z
Junior Member
**
Offline


Posts: 49
Joined: Aug 18th, 2013
Re: Problem including files in Shared Code Projects
Reply #6 - Apr 21st, 2019 at 4:56pm
Print Post  
I take your point on the subfolders.  I opened the Arduino IDE and saw a pull-out on the sketchbook menu ("Projects"), which further pulled out to the two included sketches.  That is what was new to me. The sketches would open in the IDE, but the file tabs only had the local files for each sketch, and compiling did not find any of the shared code.  The build folder did not have the shared files. 

So Arduino compatibility would require some work, which does not bother me too much.  For development, there is now no way I will abandon VS/VM/Intellisense.  It would drive me mad to have to use the Arduino IDE.

I did take the time to reorganize the local libraries as you suggested, though the project they are borrowed from is not very active.  As you say, a much cleaner approach.

Thanks again.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint