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 extern cpp source file could not include internal header file (Read 1293 times)
Cong Quyen Knight
Junior Member
**
Offline


Posts: 22
Joined: Nov 29th, 2021
extern cpp source file could not include internal header file
Dec 4th, 2021 at 6:50am
Print Post  
Hi,

I have a project as below
--src
   + --- sketch1
           + --- entry.ino
           + --- process_control.cpp
           + --- logger.h
           * --- logger_helper.h      (link to lib_logger via filter of vs2019)
           * --- logger_helper.cpp      (link to lib_logger via filter of vs2019)
   + --- sketch2
           + --- entry.ino
           + --- process_control.cpp
           + --- logger.h
           * --- logger_helper.h      (link to lib_logger via filter of vs2019)
           * --- logger_helper.cpp      (link to lib_logger via filter of vs2019)
   + --- lib_logger
           + --- logger_helper.h
           + --- logger_helper.cpp

* meaning add external file from outside sketch folder.

in process control.cpp, I could include logger_helper.h to use function here.
but in logger_helper.cpp, I could not include logger.h.
It's useful if I could add/remove some definition to enable/disable logger for only sketch1 or sketch2. Not need to disable from logger_helper.h (will affect both sketchs)
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: extern cpp source file could not include internal header file
Reply #1 - Dec 4th, 2021 at 3:15pm
Print Post  
It's not exactly clear but you might need to understand some build arduino rules and then, optionally, know how to extend that with vMicro ...

Arduino expects source code in a folder with same name as the project. Therefore an arduino project/sketch would be:-

sketch1
   sketch1.ino
   sketch1_another.ino
   cpp/h files as you have

sketch2
   sketch2.ino
   sketch2_another.ino
   cpp/h files as you have


If you want to add code to a sub folder below a sketch you must use a folder called "src". All folder can

sketch1
   sketch1.ino
   src/mycode1.cpp
   src/another_folder/mycode2.cpp

.ino files always go in the root of the project


You can include external files a couple of ways:-

1) Add individual files as a shortcut. This is a crude system, the linked shortcuts will be copied to the temp version of the project folder at build time. They will always be considered as in the project folder. (right click the project > add > existing item > select a file and note the "Add" option at the bottom of the window, select "Add as link")

2) Use a shared project (file>add>new>shared c++ project). When you use a shared project you will see that you can also add a "Reference" to the shred project to all of your arduino sketch projects (right click References>add reference>shared project).

Using 2) shared projects is recommended because you have more control over the sub folder structure and also the location of the shared code is easier to see/manage

This video might help.

https://www.visualmicro.com/page/vMicro-Videos.aspx#XPlatformSharedCode
https://www.visualmicro.com/page/vMicro-Videos.aspx#XPlatformAddToExisting

Does this make sense?
















« Last Edit: Dec 4th, 2021 at 3:37pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Cong Quyen Knight
Junior Member
**
Offline


Posts: 22
Joined: Nov 29th, 2021
Re: extern cpp source file could not include internal header file
Reply #2 - Dec 9th, 2021 at 12:04am
Print Post  
Tim@Visual Micro wrote on Dec 4th, 2021 at 3:15pm:
It's not exactly clear but you might need to understand some build arduino rules and then, optionally, know how to extend that with vMicro ...

Arduino expects source code in a folder with same name as the project. Therefore an arduino project/sketch would be:-

sketch1
   sketch1.ino
   sketch1_another.ino
   cpp/h files as you have

sketch2
   sketch2.ino
   sketch2_another.ino
   cpp/h files as you have


If you want to add code to a sub folder below a sketch you must use a folder called "src". All folder can

sketch1
   sketch1.ino
   src/mycode1.cpp
   src/another_folder/mycode2.cpp

.ino files always go in the root of the project


You can include external files a couple of ways:-

1) Add individual files as a shortcut. This is a crude system, the linked shortcuts will be copied to the temp version of the project folder at build time. They will always be considered as in the project folder. (right click the project > add > existing item > select a file and note the "Add" option at the bottom of the window, select "Add as link")

2) Use a shared project (file>add>new>shared c++ project). When you use a shared project you will see that you can also add a "Reference" to the shred project to all of your arduino sketch projects (right click References>add reference>shared project).

Using 2) shared projects is recommended because you have more control over the sub folder structure and also the location of the shared code is easier to see/manage

This video might help.

https://www.visualmicro.com/page/vMicro-Videos.aspx#XPlatformSharedCode
https://www.visualmicro.com/page/vMicro-Videos.aspx#XPlatformAddToExisting

Does this make sense?


















Shared Code help a lots. Thanks Cheesy Cheesy Cheesy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint