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
Hot Topic (More than 8 Replies) Can't use libraries in subfiles (Read 8365 times)
Robert12
Newbies
*
Offline


Posts: 5
Joined: Dec 23rd, 2013
Can't use libraries in subfiles
Dec 23rd, 2013 at 9:36pm
Print Post  
Hi,
I'm new to this Forum and the Visual Micro software. I read in the Tutorial that i can create new C or C++ items. But wehen i do that, i can't use any of the libraries. The compiler allways says "Not defined in that scope". Wehen i include the headers for that lib it says its Double defined. I just tried it without classes. Will that solve my Problems? Or do i have to "register" the files somewhere?

Thanks for help and best regards
Rob
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can't use libraries in subfiles
Reply #1 - Dec 23rd, 2013 at 9:50pm
Print Post  
Hi Robert,

Yes with Arduino if you create additional ccp/c/h files you need to manually #include libraries.

Alternatively you can create additional .ino (sketch) source files. You might already know this and have discarded the idea. 

Depending on your point of view, the additional .ino sketch files can be quite useful because they are combined together during compilation so share the same includes, variables, methods etc. Libraries only need to be declared in the main .ino file.

All of this is standard Arduino stuff which means you can also use the arduino.cc wiki, playground and forum where you might get clearer answers.

One question about "double defined". Did you place the .c #include within "#ifndef _SOURCE FILE NAME_h" of the .h?

Thanks

« Last Edit: Dec 23rd, 2013 at 9:51pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Robert12
Newbies
*
Offline


Posts: 5
Joined: Dec 23rd, 2013
Re: Can't use libraries in subfiles
Reply #2 - Dec 24th, 2013 at 10:41am
Print Post  
Hi And thanks for the fast answere.
Ok i will try it with ino files.
I created a new c item. Visual Micro created the c and h file. And then i tried to include the liquidCrystal.h, for example, in my c and h file. But both didn't worked. Now i try it with the ino file. 

Thanks and regards 
Rob.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can't use libraries in subfiles
Reply #3 - Dec 24th, 2013 at 4:46pm
Print Post  
No probs, C++ might be easier than C and .ino files are the simplest. 

Don't forget that all .ino files are combined into a single source for compile. All prototypes are automatically created for .ino files. It is an easy way to keep code organized without needing to worry about libraries, variables, static etc.
  
Back to top
IP Logged
 
Robert12
Newbies
*
Offline


Posts: 5
Joined: Dec 23rd, 2013
Re: Can't use libraries in subfiles
Reply #4 - Dec 24th, 2013 at 9:33pm
Print Post  
Thank you very much and merry christmas. 

But one last question, i have to create and include the ino files by my self, or is there a "create new" Button i didn't found yet?


Robert.
« Last Edit: Dec 24th, 2013 at 9:36pm by Robert12 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can't use libraries in subfiles
Reply #5 - Dec 24th, 2013 at 9:47pm
Print Post  
Thanks

There are menu items on the project tool bar button and also if you right click a project name in the solution explorer.

Add new sketch source (pde/ino)
Add new c item
Add new cpp item

Hopefully you used the C or the Cpp options when you attempted to add your sources previously. Or you might have discovered you can manually add c/cpp to the project using the standard Atmel or Visual Studio "Add source to project" features.

The 3 options mentioned above are controlled by Visual Micro and provide all the workflows to ensure a valid addition to the Arduino project. 

EDIT: However with ino/pde files there is no real difference to adding a file manually. The way Arduino works is that ANY pde/ino files in the sketch folder are automatically compiled and the Arduino core (api) is automatically included based upon the selected board (micro controller). Therefore, code functions such as millis() are automatically available to all pde/ino sketch sources without the need for #includes.

To answer your question, no you do not have to include the ino/pde files. All of this happens automatically for ino/pde.

One last point for new Arduino users. All the sketch source code must exist in the sketchs' folder. Sub directories with sources are not supported.

Happy holiday
« Last Edit: Dec 24th, 2013 at 10:08pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Robert12
Newbies
*
Offline


Posts: 5
Joined: Dec 23rd, 2013
Re: Can't use libraries in subfiles
Reply #6 - Dec 24th, 2013 at 10:00pm
Print Post  
Thank you very much. 
Happy Holiday.
  
Back to top
 
IP Logged
 
Robert12
Newbies
*
Offline


Posts: 5
Joined: Dec 23rd, 2013
Re: Can't use libraries in subfiles
Reply #7 - Dec 25th, 2013 at 11:21am
Print Post  
Hi,
I did what you said, and it worked.
But now I have another problem.

I declared my class in Timer.ino:
Code
Select All
class _CDimmer : IntervalTimer {
private:
	// Daten
	_Heute Heute;
	elapsedMillis	test;

	// Funktionen
	int getDimmIntervall( int data );
	void getHeute( unsigned int Datensatz );

public:
	_CDimmer();
	~_CDimmer();

	void Setup();
	void Dimmer( void );
} Dimmer; 



but when I want to use it in the main program:
Code
Select All
// Objekte
extern _CDimmer	Dimmer;

void setup()
{
	pinMode( PIN_INTERN_LED, OUTPUT );
	digitalWrite( PIN_INTERN_LED, 255 );

	Serial.begin( 9600 );
	delay( 5000 );

	//DisplaySetup();
	//Dimmer_Setup();
	Dimmer.Setup();
	....
} 



I get this message from the compiler:
Quote:
Compiling 'TerrariumController' for 'Teensy 3.0'
TerrariumController.ino : '_CDimmer' does not name a type
TerrariumController.ino : : In function 'void setup()':
TerrariumController.ino : 'Dimmer' was not declared in this scope
Error compiling


Am I wrong about classes in arduio?
Or how can I fix it?

Thanks again and happy Holidays
Rob
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Can't use libraries in subfiles
Reply #8 - Dec 26th, 2013 at 2:32pm
Print Post  
Hi,

It's best to ask these questions on the arduino.cc forum

The Visual Micro forum is really designed just to help people get the add-in working and because it is free doesn't allow me to support general Arduino questions. 

You now have an Arduino compatible installation which means you would have the same question if you were using the Arduino Ide which is where arduino.cc and the Arduino.cc playground will help.

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