Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Setting compile order of .ino / .cpp files (Read 177 times)
Abbott HMG
Newbies
*
Offline



Posts: 3
Bedford, NY, USA
Setting compile order of .ino / .cpp files
May 20th, 2019 at 4:00pm
 
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
Back to top
 

HMGVacuum.ino (8 KB | 6 )
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Setting compile order of .ino / .cpp files
Reply #1 - May 20th, 2019 at 5:38pm
 
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
 
WWW  
IP Logged
 
Abbott HMG
Newbies
*
Offline



Posts: 3
Bedford, NY, USA
Re: Setting compile order of .ino / .cpp files
Reply #2 - Jun 13th, 2019 at 11:10pm
 
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++):
#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++):
	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
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Setting compile order of .ino / .cpp files
Reply #3 - Jun 13th, 2019 at 11:16pm
 
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>

Back to top
« Last Edit: Jul 4th, 2019 at 9:51pm by Visual Micro »  
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print