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 Setting compile order of .ino / .cpp files (Read 3944 times)
Abbott HMG
Junior Member
**
Offline


Posts: 59
Location: Bedford, NY, USA
Joined: May 10th, 2019
Setting compile order of .ino / .cpp files
May 20th, 2019 at 3:00pm
Print Post  
I have a top-heavy .ino file with lots of classes that precede my code. It all works except if I put the classes in separate cpp files. For maintenance convenience and clarity  I'll try to put the various classes into libraries (but they're not libraries).
It would be easier to create cpp/h files and tell Vmicro what order to compile them in, since they must be known (parsed by) the compiler prior to parsing the .ino. Just compiling the multiple files gives me reference errors.
I understand that this works in the Arduino IDE by using tabs and naming modules in the reverse order of compile (1module.ino, 2class.cpp, 3class.cpp. 4class.cpp) a class that invokes another must have a lower number.
See attached .ino. 
Embarrassed
Abbott
  

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


Posts: 12166
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Setting compile order of .ino / .cpp files
Reply #1 - May 20th, 2019 at 4:38pm
Print Post  
Hi

I think some confusion. cpp files are supported but they must be in the project folder or in a folder called \src below the project or any folder below the src folder.

cpp files are highly recommended and should build fine. The names of cpp files is not important, the linker works out the order.

For multiple .ino files the names are important and define the order that they are all combined into a cpp file in the temp build folder. It is the resulting cpp of the combined ino files that is compiled. However the project_name.ino will always be first.

Putting classes in the ino files is not recommended at all.

If you cpp files reference libraries then either make sure the "vmicro>compiler>deep search" is enabled (which it is by default) or make sure all of your library #includes are also in the project_name.ino

If you create any user types such as structs in the .ino files that are used in the signature of methods in the same file then make sure you also add the prototypes between where the type is defined and the first method that uses the type in its signature.

If you create an object from a class in a .cpp and need to use it in the .ino then then mark the object as extern for it to be found by the .ino code.

If you create seperate cpp/h make sure you add the #include <arduino.h> which is automatically added to the temp .ino code prior to compile so you won't see it in the .ino code.

If you are using avr, then click "vMicro>show/hide hidden files" and look at how the arduino core works. HardwareSerial.cpp/h is a good example which shows Serial, Serial1 etc being defined and created.

Does this help?

  
Back to top
IP Logged
 
Abbott HMG
Junior Member
**
Offline


Posts: 59
Location: Bedford, NY, USA
Joined: May 10th, 2019
Re: Setting compile order of .ino / .cpp files
Reply #2 - Jun 13th, 2019 at 10:10pm
Print Post  
Thanks for the response. 
I originally had 12 cpp files but included them in ino to clean compile.

I now have the following cpp with the call below:


Code (C++)
Select All
#include<Arduino.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Clcd.h> // i2c LCD i/o class header
//#include "LCDManager.h"

static hd44780_I2Clcd* lcd;
class LcdManager {
public:
	static void PrintLn(String message, int rowNo = 0) {
		if (rowNo == 0) {
			lcd->setCursor(0, 0);
		}
		else {
			lcd->setCursor(0, 1);
		}
		lcd->print(message);
	}
	static void Init() {
		lcd = new hd44780_I2Clcd(_lcd_addr);
		lcd->begin(2, 16);
		// Turn on the blacklight and print a message.
		lcd->backlight();
		lcd->clear();
		lcd->print(START_MSG);
	}
}; 



Called by:

Code (C++)
Select All
	void Setup() {
		Serial.begin(9600);// start serial port
		Serial.println("Vacuum Test");
		LcdManager::Init();
	} 



I get LcdManager not defined error
do I need an extern ... and where
Thanks
Abbott
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12166
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Setting compile order of .ino / .cpp files
Reply #3 - Jun 13th, 2019 at 10:16pm
Print Post  
If you use the Add Code > C++ class and header to add a class called "MyTestMeClass" you will see that an object is created called MyTestMe based on the MyTextMeClass and that it is available to the ino code.

I'm not the expert when it comes to code syntax, it's just whatever arduino supports, therefore you can ask on other forums that are designed for code questions.

note: When adding arduino libraries never use a path, just the .h name

#include <hd44780_I2Clcd.h>

NOT

#include <hd44780ioClass/hd44780_I2Clcd.h>

« Last Edit: Jul 4th, 2019 at 8:51pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint