Forum: Compiler & IDEs Probleme mit delay.h


von Thomas W. (xote)


Lesenswert?

Hallo Forum,

gerade wollte ich mit C und dem AVR anfangen, und jetzt kriege ich schon 
einen Fehler beim kompilieren und verstehe nicht warum.

mein Program (eh super-kurz):
1
#define F_CPU 3686400UL
2
#include <util/delay.h>
3
4
int main(void)
5
{
6
    while(1)
7
    {
8
        _delay_ms(1000);
9
    }
10
    return 0;
11
}
1
Compiling: main.c
2
avr-gcc -c -mmcu=atmega8 -I. -gdwarf-2   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=main.lst  -std=c89 -DF_OSC=3686400 -MD -MP -MF .dep/main.o.d main.c -o main.o 
3
In file included from /usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay.h:39,
4
                 from main.c:2:
5
/usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay_basic.h:65: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
6
/usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay_basic.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
7
In file included from main.c:2:
8
/usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay.h:79: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
9
/usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay.h:80: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
10
make: *** [main.o] Fehler 1

Was ich bis jetzt rausgefunden habe ist, dass es mit dem GNU99 
C-Standard geht, mit ANSI-C nicht. Ist die avr-libc nicht ANSI-C 
tauglich? Ich verwende im Übrigen das template Makefile aus der AVR-GCC 
Tutorial Ecke oben links...

mfg
Thomas

von troll (Gast)


Lesenswert?

fehlt da nicht ein #include <avr/io.h>?

von Klaus W. (mfgkw)


Lesenswert?

Warum lässt du nicht einfach -std=c89 weg? Brauchst du das?

von Klaus W. (mfgkw)


Lesenswert?

troll schrieb:
> fehlt da nicht ein #include <avr/io.h>?

ja, aber das ändert nichts.

von Thomas W. (xote)


Lesenswert?

troll schrieb:
> fehlt da nicht ein #include <avr/io.h>?

Ja, den Header werde ich mit Sicherheit noch brauchen. Ändert aber am 
Verhalten nix. ANSI-C scheint nicht zu gehen, mit GNU-Extensions aber 
schon (im Makefile wäre das "gnu89").

Brauchen tu ich das jetzt nicht. Ich dachte halt, es würde mit ANSI-C 
auch gehen, tuts aber eben nicht.

mfg
Thomas

von Thomas W. (xote)


Lesenswert?

In der Beschreibung der avr-libc steht zu lesen:
1
In general, it has been the goal to stick as best as possible to
2
established standards while implementing this library. Commonly, this
3
refers to the C library as described by the ANSI X3.159-1989 and ISO/IEC
4
9899:1990 ("ANSI-C") standard, as well as parts of their successor ISO/IEC
5
9899:1999 ("C99"). Some additions have been inspired by other standards
6
like IEEE Std 1003.1-1988 ("POSIX.1"), while other extensions are purely
7
AVR-specific (like the entire program-space string interface).

Ich nehme daher an, es ist schon alleine wegen der avr-libc nicht egal 
nach welchem C-Standard man ein Program mit der Makefile-Vorlage 
kompiliert.

mfg
Thomas

von Johann L. (gjlayde) Benutzerseite


Lesenswert?

Hilf ein
1
#define inline __inline
vor dem #include?

Bzw
 
-Dinline=__inline 
 
als Option.

von Jörg W. (dl8dtl) (Moderator) Benutzerseite


Lesenswert?

Thomas Wursch schrieb:
> Was ich bis jetzt rausgefunden habe ist, dass es mit dem GNU99
> C-Standard geht, mit ANSI-C nicht.

Bitte schreib' einen Bugreport:

https://savannah.nongnu.org/bugs/?group=avr-libc

(Johann hat den Finger drauf.)

von Johann L. (gjlayde) Benutzerseite


Lesenswert?


von Jörg W. (dl8dtl) (Moderator) Benutzerseite


Lesenswert?

Danke!

Ich denke, ich werde nach der Sommerpause mal einen Release in Angriff
nehmen.

von Thomas W. (xote)


Lesenswert?

Danke an Alle soweit!

Damit komme ich erstmal weiter. Und danke auch an Johann, als C-Neuling 
wäre mein Bugreport erbärmlich dürftig gewesen ;-)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.