Can't use util/delay.h on c++ in Avrstudio v6

Need help with C, C++, perl, python, etc?

Can't use util/delay.h on c++ in Avrstudio v6

Postby zhihu » 2017-10-23 06:09

I'm just new with microcontrollers and I'm hoping someone could help me understand this. I'm using an AVRStudio 6 and an AVRDragon. Watched some tutorials on basic programming.

Here's the code:

#include <util/delay.h>
int main(void) {
_delay_ms(30);
}
What I can't understand is when I made a new avrgcc c project it works well. But as a c++ fan, I made a new project using avrgcc c++ and the code won't work. The error message is as follows:

2. 'fabs' was not declared in this scope
3. 'ceil' was not declared in this scope
4. 'fabs' was not declared in this scope
5. 'ceil' was no declared in this scope
I tried those codes in my avrsudio v6 by avrgcc c++ program and the warning #1 goes away but the other 4 warnings are still there? If I use avrgcc c there are no problems. What must I do so I could do this with avrgcc c++? Can anyone help me understands whats going on? Thanks a lot guys!
zhihu
 
Posts: 1
Joined: 2017-10-23 05:46

Re: Can't use util/delay.h on c++ in Avrstudio v6

Postby reinob » 2017-10-23 11:27

zhihu wrote:I'm just new with microcontrollers and I'm hoping someone could help me understand this. I'm using an AVRStudio 6 and an AVRDragon. Watched some tutorials on basic programming.

Here's the code:

#include <util/delay.h>
int main(void) {
_delay_ms(30);
}
What I can't understand is when I made a new avrgcc c project it works well. But as a c++ fan, I made a new project using avrgcc c++ and the code won't work. The error message is as follows:

2. 'fabs' was not declared in this scope
3. 'ceil' was not declared in this scope
4. 'fabs' was not declared in this scope
5. 'ceil' was no declared in this scope
I tried those codes in my avrsudio v6 by avrgcc c++ program and the warning #1 goes away but the other 4 warnings are still there? If I use avrgcc c there are no problems. What must I do so I could do this with avrgcc c++? Can anyone help me understands whats going on? Thanks a lot guys!


I don't know how that _delay_ms() function is defined, but it could be a macro using math functions without bothering to #include <math.h>

You'll have to do it yourself then..
reinob
 
Posts: 520
Joined: 2014-06-30 11:42

Re: Can't use util/delay.h on c++ in Avrstudio v6

Postby pylkko » 2017-10-23 11:41

Is this on Debian 9.2?

You need to include the math header file.

That is, only delay will not suffice.
first include math.h and then util/delay.h

or add the include math to the delay.h file header

8 bit avr is a really primitive architecture with no floating point math (FPU) so people often try to avoid doing math...

However, just take a look at how difficult and complex it is using c++ on avr (google around) and you wil get an idea of why barely anyone uses it, or at least some avoid. I wouldn't, but then again I don't know what you are doing.

http://www.atmel.com/webdoc/avrlibcrefe ... splus.html
User avatar
pylkko
 
Posts: 1174
Joined: 2014-11-06 19:02


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable