Forum: Compiler & IDEs "expected ')' before '*' token" -- Was ist da los?


von Robert S. (razer) Benutzerseite


Lesenswert?

Hallo an alle,

Ich versuche schon seit ein paar Stunden meinen Source Code zu 
kompilieren :(

Jedoch bekomme ich immer diese Fehlermeldung "expected ')' before '*' 
token".

In der parser.c ist die Funktion parser(CANMessage *msg) implementiert. 
Im zugehörigen Header der Prototyp. Die Struktur CANMessage ist in der 
Datei can.h definiert.

Jedoch will das nicht klappen :(

parser.h:
1
 #ifndef PARSER_H
2
 #define PARSER_H
3
 
4
 #include "boot.h"
5
 #include "can.h"
6
7
 #define GET_PAGE_SETTINGS  0x00
8
 #define GET_FLASH_DATA    0x01
9
 #define FLASH_PAGE      0x02
10
 #define START_APP      0x03
11
 
12
  void parser(CANMessage *msg);
13
    
14
  void (*jump_to_app)( void ) ;
15
  
16
 #endif

parser.c
1
 #include "parser.h"
2
 
3
typedef struct Flashpage
4
{
5
  unsigned char buf[150];
6
  unsigned char pageNr;
7
  unsigned int pagesize;
8
  unsigned char *ptr;
9
} sFlashPage;
10
11
sFlashPage flashPage;
12
13
 void (*jump_to_app)( void ) = 0x0000;
14
 
15
 void parser(CANMessage *msg)
16
 {
17
  switch(msg->data[0])
18
  {
19
    case GET_PAGE_SETTINGS:
20
      flashPage.pagesize = (unsigned int) msg->data[1] << 8;
21
      flashPage.pagesize |= msg->data[2];
22
      flashPage.pageNr = msg->data[3];
23
      flashPage.ptr = &flashPage.buf[0];
24
    break;
25
    case GET_FLASH_DATA:
26
      for(unsigned char i = 1; i < 7; i++)
27
        *(flashPage.ptr++) = msg->data[i];
28
    break;
29
    case FLASH_PAGE:
30
      boot_program_page (flashPage.pageNr, flashPage.buf);
31
    break;
32
    case START_APP:
33
      jump_to_app();
34
    break;
35
    
36
  }
37
}

can.h
1
#ifndef CAN_H
2
 #define CAN_H
3
 
4
 #include "mcp2515.h"
5
 #include "parser.h"
6
 #include "spi.h"
7
 #include "avr/interrupt.h"
8
 
9
 #define TX_RTS_DDR    DDRB
10
 #define TX_RTS_PORT  PORTB
11
 #define TX_RTS0    PB0    
12
 #define TX_RTS1    PB1
13
 #define TX_RTS2    PB3
14
 
15
 #define setOutput(ddr, pin)  (ddr |= (1 << pin))
16
 #define setInput(ddr, pin)    (ddr &= ~(1 << pin))
17
 #define setPin(port, pin)    (port |= (1 << pin))
18
 #define clearPin(port, pin)  (port &= ~(1 << pin))
19
 
20
 #define sendBuffer0()      setPin(TX_RTS_PORT, TX_RTS0)
21
 #define sendBuffer1()      setPin(TX_RTS_PORT, TX_RTS1)
22
 #define sendBuffer2()      setPin(TX_RTS_PORT, TX_RTS2)
23
 
24
 typedef struct sCANMessage
25
{
26
    uint16_t  id;
27
    uint8_t   rtr;
28
    uint8_t   length;
29
    uint8_t   data[8];
30
} CANMessage;
31
 #endif

Weiß jemand was los ist?
Ich hoffe es aknn jemand helfen.

Gruß Robert

von Chris (Gast)


Lesenswert?

Ist das die einzige Fehlermeldung? Falls ja, auf welche Zeile bezieht 
die sich?

von Robert S. (razer) Benutzerseite


Lesenswert?

Diese Fehlermeldung bezieht sich auf die Zeile, in der die Funktion 
parser() in parser.h deklariert wird.

Es gibt noch eine 2. und zwar beim Aufruf der Funktion Parser in can.c

Gruß Robert

von Uhu U. (uhu)


Lesenswert?

Die Fehlermeldung bedeutet, daß bei

   void parser(CANMessage *msg);

der Typ CANMessage nicht bekannt ist.

Setz mal direkt vor #include "can.h" folgenden Text.

   #ifdef CAN_H
   #error CAN_H ist definiert
   #endif

Wenn der Compiler den Text nach #error als Fehlermeldung anzeigt, dann 
ist CAN_H bereits definiert und deswegen wird der Inhalt deines Headers 
can.h nicht ausgewertet.

von Robert S. (razer) Benutzerseite


Lesenswert?

Ich habs jetzt
1
 #ifndef PARSER_H
2
 #define PARSER_H
3
 
4
 #include "boot.h"
5
 
6
 #ifdef CAN_H
7
 #error CAN_H ist definiert
8
 #endif
9
 
10
//#include "can.h"
11
 
12
  void parser(CANMessage *msg);
13
    
14
  void (*jump_to_app)( void ) ;
15
  
16
 #endif

Ist #include "can.h" auskommentiert, bekomm ich die gleich Fehermeldung. 
Wenn es drinnen ist, bekomm ich diese Fehlermeldungen:
1
                 from can.c:20:
2
parser.h:26:3: error: #error CAN_H ist definiert
3
In file included from can.h:24,
4
                 from can.c:20:
5
parser.h:31: error: expected ')' before '*' token
6
can.c: In function '__vector_1':
7
can.c:205: warning: implicit declaration of function 'parser'

Hat leider auch nicht geklappt.

Gruß Robert

von Uhu U. (uhu)


Lesenswert?

Doch, hat prima geklappt!

Das einzige, was du jetzt noch machen mußt, ist, für dein privates CAN_H 
ein anderes Symbol auswählen - CAN_H wird vom Compiler bereits 
verwendet! (Und natürlich das #ifdef... Zeug wieder rauslöschen.)

Generell ist es keine gute Idee, Symbole nach diesem Muster selbst zu 
definierten - die sind nämlich für den Compiler reserviert.

Mach dich mal schlau, was #ifdef und #error machen.

von Robert S. (razer) Benutzerseite


Lesenswert?

Uhu Uhuhu wrote:
> Doch, hat prima geklappt!

error: #error CAN_H ist definiert: Dachte wegen dem #error, da das auch 
mit ausgegeben wurde hat nicht geklappt...


> Das einzige, was du jetzt noch machen mußt, ist, die für dein privates
> CAN_H ein anderes Symbol auswählen - CAN_H wird vom Compiler bereits
> verwendet! (Und natürlich das #ifdef... Zeug wieder rauslöschen.)

Es wird doh nur meine eigene CAN_H verwendet. Mehrfach einbindungen in 
verschiedenen C Files sind ja möglich.

Muss ich demnach CAN_H in zB AVR_CAN_H umbenennen?

Gruß Robert

von Uhu U. (uhu)


Lesenswert?

Und warum ist CAN_H dann definiert? Wenn du es bis zu dem #ifdef CAN_H 
nicht selbst gemacht hast, dann wird es in boot.h oder einer dort 
includierten Datei gemacht, oder per -D-Option über den Makefile.

AVR_CAN_H ist OK.

Es könnte sein, daß der gcc kein #error kann - lies mal nach. Aber auch 
wenn er es nicht kann, hat der Trick funktioniert.

von Robert S. (razer) Benutzerseite


Lesenswert?

Wenn ich alles in AVR_CAN_H umbenenne hab ich aber das gleiche Problem.

von Uhu U. (uhu)


Lesenswert?

> //#include "can.h"

Ist das wieder entkommentiert?

Was passiert, wenn du

   #ifndef CAN_H
   #define CAN_H

und

   #endif

in can.h auskommentierst?

von Robert S. (razer) Benutzerseite


Lesenswert?

Uhu Uhuhu wrote:
>> //#include "can.h"
>
> Ist das wieder entkommentiert?

Ja

> Was passiert, wenn du
>
>    #ifndef CAN_H
>    #define CAN_H
>
> und
>
>    #endif
>
> in can.h auskommentierst?

Dann bekomm ich die Fehlermeldung:
1
In file included from avr_can.c:20:
2
avr_can.h:44: error: redefinition of 'struct sCANMessage'
3
avr_can.h:49: error: redefinition of typedef 'CANMessage'
4
avr_can.h:49: error: previous declaration of 'CANMessage' was here

von Uhu U. (uhu)


Lesenswert?

Aha, interessant.

Dann ändere mal den Namen deiner sCANMessage und CANMessage.

Offensichtlich wird doch schon irgendwo CAN-Zeug reingezogen...

Wie sieht denn dein Makefile aus?

von Robert S. (razer) Benutzerseite


Lesenswert?

Ich hab das ganze in sCANMsg und CANMsg geändert, doch der gleiche 
Effekt...

Edit:
Mein Makefile:
1
# Hey Emacs, this is a -*- makefile -*-
2
#
3
# WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
4
# Released to the Public Domain
5
# Please read the make user manual!
6
#
7
# Additional material for this makefile was submitted by:
8
#  Tim Henigan
9
#  Peter Fleury
10
#  Reiner Patommel
11
#  Sander Pool
12
#  Frederik Rouleau
13
#  Markus Pfaff
14
#
15
# On command line:
16
#
17
# make all = Make software.
18
#
19
# make clean = Clean out built project files.
20
#
21
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).
22
#
23
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
24
#                4.07 or greater).
25
#
26
# make program = Download the hex file to the device, using avrdude.  Please
27
#                customize the avrdude settings below first!
28
#
29
# make filename.s = Just compile filename.c into the assembler code only
30
#
31
# To rebuild project do "make clean" then "make all".
32
#
33
34
# mth 2004/09 
35
# Differences from WinAVR 20040720 sample:
36
# - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)
37
# - F_OSC Define in CFLAGS and AFLAGS
38
39
40
# MCU name
41
MCU = atmega32
42
43
# Main Oscillator Frequency
44
# This is only used to define F_OSC in all assembler and c-sources.
45
F_OSC = 16000000 
46
47
# Output format. (can be srec, ihex, binary)
48
FORMAT = ihex
49
50
# Target file name (without extension).
51
TARGET = main
52
53
54
# List C source files here. (C dependencies are automatically generated.)
55
SRC = $(TARGET).c spi.c mcp2515.c avr_can.c boot.c parser.c
56
57
58
# List Assembler source files here.
59
# Make them always end in a capital .S.  Files ending in a lowercase .s
60
# will not be considered source files but generated files (assembler
61
# output from the compiler), and will be deleted upon "make clean"!
62
# Even though the DOS/Win* filesystem matches both .s and .S the same,
63
# it will preserve the spelling of the filenames, and gcc itself does
64
# care about how the name is spelled on its command-line.
65
ASRC = 
66
67
68
69
# Optimization level, can be [0, 1, 2, 3, s]. 
70
# 0 = turn off optimization. s = optimize for size.
71
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
72
OPT = s
73
74
# Debugging format.
75
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
76
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
77
#DEBUG = stabs
78
#DEBUG = dwarf-2
79
80
# List any extra directories to look for include files here.
81
#     Each directory must be seperated by a space.
82
EXTRAINCDIRS = 
83
84
85
# Compiler flag to set the C Standard level.
86
# c89   - "ANSI" C
87
# gnu89 - c89 plus GCC extensions
88
# c99   - ISO C99 standard (not yet fully implemented)
89
# gnu99 - c99 plus GCC extensions
90
CSTANDARD = -std=gnu99
91
92
# Place -D or -U options here
93
CDEFS =
94
95
# Place -I options here
96
CINCS =
97
98
99
# Compiler flags.
100
#  -g*:          generate debugging information
101
#  -O*:          optimization level
102
#  -f...:        tuning, see GCC manual and avr-libc documentation
103
#  -Wall...:     warning level
104
#  -Wa,...:      tell GCC to pass this to the assembler.
105
#    -adhlns...: create assembler listing
106
CFLAGS = -g$(DEBUG)
107
CFLAGS += $(CDEFS) $(CINCS)
108
CFLAGS += -O$(OPT)
109
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
110
CFLAGS += -Wall -Wstrict-prototypes
111
#CFLAGS += -Wall
112
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
113
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
114
CFLAGS += $(CSTANDARD)
115
CFLAGS += -DF_OSC=$(F_OSC)
116
117
118
119
# Assembler flags.
120
#  -Wa,...:   tell GCC to pass this to the assembler.
121
#  -ahlms:    create listing
122
#  -gstabs:   have the assembler create line number information; note that
123
#             for use in COFF files, additional information about filenames
124
#             and function names needs to be present in the assembler source
125
#             files -- see avr-libc docs [FIXME: not yet described there]
126
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
127
ASFLAGS += -DF_OSC=$(F_OSC)
128
129
130
#Additional libraries.
131
132
# Minimalistic printf version
133
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
134
135
# Floating point printf version (requires MATH_LIB = -lm below)
136
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
137
138
PRINTF_LIB = 
139
140
# Minimalistic scanf version
141
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
142
143
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
144
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
145
146
SCANF_LIB = 
147
148
MATH_LIB = -lm
149
150
# External memory options
151
152
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
153
# used for variables (.data/.bss) and heap (malloc()).
154
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
155
156
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
157
# only used for heap (malloc()).
158
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
159
160
EXTMEMOPTS =
161
162
# Linker flags.
163
#  -Wl,...:     tell GCC to pass this to linker.
164
#    -Map:      create map file
165
#    --cref:    add cross reference to  map file
166
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
167
LDFLAGS += $(EXTMEMOPTS)
168
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
169
170
171
172
173
# Programming support using avrdude. Settings and variables.
174
175
# Programming hardware: alf avr910 avrisp bascom bsd 
176
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
177
#
178
# Type: avrdude -c ?
179
# to get a full listing.
180
#
181
AVRDUDE_PROGRAMMER = stk500
182
183
# com1 = serial port. Use lpt1 to connect to parallel port.
184
AVRDUDE_PORT = com2    # programmer connected to serial device
185
186
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
187
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
188
189
190
# Uncomment the following if you want avrdude's erase cycle counter.
191
# Note that this counter needs to be initialized first using -Yn,
192
# see avrdude manual.
193
#AVRDUDE_ERASE_COUNTER = -y
194
195
# Uncomment the following if you do /not/ wish a verification to be
196
# performed after programming the device.
197
#AVRDUDE_NO_VERIFY = -V
198
199
# Increase verbosity level.  Please use this when submitting bug
200
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
201
# to submit bug reports.
202
#AVRDUDE_VERBOSE = -v -v
203
204
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
205
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
206
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
207
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
208
209
210
211
# ---------------------------------------------------------------------------
212
213
# Define directories, if needed.
214
DIRAVR = c:/winavr
215
DIRAVRBIN = $(DIRAVR)/bin
216
DIRAVRUTILS = $(DIRAVR)/utils/bin
217
DIRINC = .
218
DIRLIB = $(DIRAVR)/avr/lib
219
220
221
# Define programs and commands.
222
SHELL = sh
223
CC = avr-gcc
224
OBJCOPY = avr-objcopy
225
OBJDUMP = avr-objdump
226
SIZE = avr-size
227
NM = avr-nm
228
AVRDUDE = avrdude
229
REMOVE = rm -f
230
COPY = cp
231
232
233
234
235
# Define Messages
236
# English
237
MSG_ERRORS_NONE = Errors: none
238
MSG_BEGIN = -------- begin --------
239
MSG_END = --------  end  --------
240
MSG_SIZE_BEFORE = Size before: 
241
MSG_SIZE_AFTER = Size after:
242
MSG_COFF = Converting to AVR COFF:
243
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
244
MSG_FLASH = Creating load file for Flash:
245
MSG_EEPROM = Creating load file for EEPROM:
246
MSG_EXTENDED_LISTING = Creating Extended Listing:
247
MSG_SYMBOL_TABLE = Creating Symbol Table:
248
MSG_LINKING = Linking:
249
MSG_COMPILING = Compiling:
250
MSG_ASSEMBLING = Assembling:
251
MSG_CLEANING = Cleaning project:
252
253
254
255
256
# Define all object files.
257
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
258
259
# Define all listing files.
260
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
261
262
263
# Compiler flags to generate dependency files.
264
### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
265
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
266
267
# Combine all necessary flags and optional flags.
268
# Add target processor to flags.
269
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
270
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
271
272
273
274
275
276
# Default target.
277
all: begin gccversion sizebefore build sizeafter finished end
278
279
build: elf hex eep lss sym 
280
281
elf: $(TARGET).elf
282
hex: $(TARGET).hex
283
eep: $(TARGET).eep
284
lss: $(TARGET).lss 
285
sym: $(TARGET).sym
286
287
288
289
# Eye candy.
290
# AVR Studio 3.x does not check make's exit code but relies on
291
# the following magic strings to be generated by the compile job.
292
begin:
293
  @echo
294
  @echo $(MSG_BEGIN)
295
296
finished:
297
  @echo $(MSG_ERRORS_NONE)
298
299
end:
300
  @echo $(MSG_END)
301
  @echo
302
303
304
# Display size of file.
305
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
306
ELFSIZE = $(SIZE) $(TARGET).elf
307
sizebefore:
308
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
309
310
sizeafter:
311
  @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
312
313
314
315
# Display compiler version information.
316
gccversion : 
317
  @$(CC) --version
318
319
320
321
# Program the device.  
322
program: $(TARGET).hex $(TARGET).eep
323
  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
324
325
326
327
328
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
329
COFFCONVERT=$(OBJCOPY) --debugging \
330
--change-section-address .data-0x800000 \
331
--change-section-address .bss-0x800000 \
332
--change-section-address .noinit-0x800000 \
333
--change-section-address .eeprom-0x810000 
334
335
336
coff: $(TARGET).elf
337
  @echo
338
  @echo $(MSG_COFF) $(TARGET).cof
339
  $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
340
341
342
extcoff: $(TARGET).elf
343
  @echo
344
  @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
345
  $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
346
347
348
349
# Create final output files (.hex, .eep) from ELF output file.
350
%.hex: %.elf
351
  @echo
352
  @echo $(MSG_FLASH) $@
353
  $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
354
#  mv main.hex main.bin
355
356
%.eep: %.elf
357
  @echo
358
  @echo $(MSG_EEPROM) $@
359
  -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
360
  --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
361
362
# Create extended listing file from ELF output file.
363
%.lss: %.elf
364
  @echo
365
  @echo $(MSG_EXTENDED_LISTING) $@
366
  $(OBJDUMP) -h -S $< > $@
367
368
# Create a symbol table from ELF output file.
369
%.sym: %.elf
370
  @echo
371
  @echo $(MSG_SYMBOL_TABLE) $@
372
  $(NM) -n $< > $@
373
374
375
376
# Link: create ELF output file from object files.
377
.SECONDARY : $(TARGET).elf
378
.PRECIOUS : $(OBJ)
379
%.elf: $(OBJ)
380
  @echo
381
  @echo $(MSG_LINKING) $@
382
  $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
383
384
385
# Compile: create object files from C source files.
386
%.o : %.c
387
  @echo
388
  @echo $(MSG_COMPILING) $<
389
  $(CC) -c $(ALL_CFLAGS) $< -o $@ 
390
391
392
# Compile: create assembler files from C source files.
393
%.s : %.c
394
  $(CC) -S $(ALL_CFLAGS) $< -o $@
395
396
397
# Assemble: create object files from assembler source files.
398
%.o : %.S
399
  @echo
400
  @echo $(MSG_ASSEMBLING) $<
401
  $(CC) -c $(ALL_ASFLAGS) $< -o $@
402
403
404
405
# Target: clean project.
406
clean: begin clean_list finished end
407
  rm main.bin
408
409
clean_list :
410
  @echo
411
  @echo $(MSG_CLEANING)
412
  $(REMOVE) $(TARGET).hex
413
  $(REMOVE) $(TARGET).eep
414
  $(REMOVE) $(TARGET).obj
415
  $(REMOVE) $(TARGET).cof
416
  $(REMOVE) $(TARGET).elf
417
  $(REMOVE) $(TARGET).map
418
  $(REMOVE) $(TARGET).obj
419
  $(REMOVE) $(TARGET).a90
420
  $(REMOVE) $(TARGET).sym
421
  $(REMOVE) $(TARGET).lnk
422
  $(REMOVE) $(TARGET).lss
423
  $(REMOVE) $(OBJ)
424
  $(REMOVE) $(LST)
425
  $(REMOVE) $(SRC:.c=.s)
426
  $(REMOVE) $(SRC:.c=.d)
427
  $(REMOVE) .dep/*
428
429
430
431
# Include the dependency files.
432
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
433
434
435
# Listing of phony targets.
436
.PHONY : all begin finish end sizebefore sizeafter gccversion \
437
build elf hex eep lss sym coff extcoff \
438
clean clean_list program

von Uhu U. (uhu)


Lesenswert?

Wie sieht denn dein Makefile aus?

von Robert S. (razer) Benutzerseite


Lesenswert?

Makefile hab ich gepostet

von Uhu U. (uhu)


Lesenswert?

> SRC = $(TARGET).c spi.c mcp2515.c avr_can.c boot.c parser.c

Na da ist doch noch ein ganzer Sack weiterer Quellfiles im Spiel und 
deine neuen Fehlermeldungen kommen aus avr_can.c, nicht aus parser.c

Jetzt mußt du dir avr_can.c näher ansehen.

von Robert S. (razer) Benutzerseite


Lesenswert?

Das is die ursprüngliche can.h/can.c die ich umbenannt habe

von Uhu U. (uhu)


Lesenswert?

Mir scheint, wir müssen das alles nochmal genau durchgehen.

Fehlermeldungen wie

   "expected ')' before '*' token"

deuten an der Stelle, an der sie bei dir auftrat, auf einen 
undefinierten Datentyp. (Die merkwürdige Art, solche Fehler zu melden, 
ist typisch für bottom-up-Parser, wie sie z.B. in C-Compilern eingesetzt 
werden.)

Das #ifdef CAN_H vor #include "can.h" war erfüllt, also muß irgendwie 
das CAN_H definiert gewesen sein.

von Andreas K. (a-k)


Lesenswert?

Wahrscheinlich wird can.h zweimal reingezogen, daher der Spuk mit CAN_H. 
Das ist aber nicht das Problem.

Was manchmal hilft:
  avr-gcc -E quellfile.c
um sich anzusehen, ob der Präprozessor irgendwelchen Unfug gestiftet 
hat.

von Robert S. (razer) Benutzerseite


Lesenswert?

Also die can.h ist in mehreren C Files inkludiert.

Also die #error CAN_H ist definiert kommt nur wenn darunter die can.h 
inkludiert wird. Andernfalls kommt nur die expected ')' before '*' token 
Fehlermeldung.

von Robert S. (razer) Benutzerseite


Lesenswert?

Also das sind die Ausgaben (nur die includes)
1
typedef uint64_t uint_least64_t;
2
# 213 "c:/winavr-20070525/bin/../avr/include/stdint.h" 3
3
typedef int8_t int_fast8_t;
4
5
6
7
8
typedef uint8_t uint_fast8_t;
9
10
11
12
13
typedef int16_t int_fast16_t;
14
15
16
17
18
typedef uint16_t uint_fast16_t;
19
20
21
22
23
typedef int32_t int_fast32_t;
24
25
26
27
28
typedef uint32_t uint_fast32_t;
29
30
31
32
33
34
35
36
typedef int64_t int_fast64_t;
37
38
39
40
41
42
43
typedef uint64_t uint_fast64_t;
44
# 273 "c:/winavr-20070525/bin/../avr/include/stdint.h" 3
45
typedef int64_t intmax_t;
46
47
48
49
50
typedef uint64_t uintmax_t;
51
# 38 "c:/winavr-20070525/bin/../avr/include/inttypes.h" 2 3
52
# 77 "c:/winavr-20070525/bin/../avr/include/inttypes.h" 3
53
typedef int32_t int_farptr_t;
54
55
56
57
typedef uint32_t uint_farptr_t;
58
# 127 "c:/winavr-20070525/bin/../avr/include/avr/sfr_defs.h" 2 3
59
# 88 "c:/winavr-20070525/bin/../avr/include/avr/io.h" 2 3
60
In file included from mcp2515.h:23,
61
                 from can.h:23,
62
                 from can.c:20:
63
c:/winavr-20070525/bin/../avr/include/avr/io.h:356:6: warning: #warning "device
64
type not defined"
65
# 360 "c:/winavr-20070525/bin/../avr/include/avr/io.h" 3
66
# 1 "c:/winavr-20070525/bin/../avr/include/avr/portpins.h" 1 3
67
# 361 "c:/winavr-20070525/bin/../avr/include/avr/io.h" 2 3
68
# 370 "c:/winavr-20070525/bin/../avr/include/avr/io.h" 3
69
# 1 "c:/winavr-20070525/bin/../avr/include/avr/version.h" 1 3
70
# 371 "c:/winavr-20070525/bin/../avr/include/avr/io.h" 2 3
71
# 24 "mcp2515.h" 2
72
# 1 "spi.h" 1
73
# 28 "spi.h"
74
 void spiMasterInit(unsigned char pre);
75
76
 unsigned char spiWrite(unsigned char data);
77
78
 unsigned char spiRead(void);
79
# 25 "mcp2515.h" 2
80
# 33 "mcp2515.h"
81
 unsigned char mcp2515_readRegister(unsigned char adress);
82
83
 void mcp2515_modifyRegister(unsigned char adress, unsigned char bitmask, unsign
84
ed char data);
85
86
  void mcp2515Init(void);
87
# 24 "can.h" 2
88
# 1 "parser.h" 1
89
In file included from can.h:24,
90
                 from can.c:20:
91
parser.h:24:5: error: #error CAN_H ist definiert
92
# 28 "parser.h"
93
# 1 "boot.h" 1
94
# 23 "boot.h"
95
     void boot_program_page (uint32_t page, uint8_t *buf);
96
# 29 "parser.h" 2
97
98
  void parser(CANMsg *msg);
99
100
  void (*jump_to_app)( void ) ;
101
# 25 "can.h" 2
102
103
# 1 "c:/winavr-20070525/bin/../avr/include/avr/interrupt.h" 1 3
104
# 27 "can.h" 2
105
# 43 "can.h"
106
 typedef struct sCANMsg
107
{
108
    uint16_t id;
109
    uint8_t rtr;
110
    uint8_t length;
111
    uint8_t data[8];
112
} CANMsg;
113
# 21 "can.c" 2
114
115
116
117
118
119
120
typedef struct Flashpage
121
{
122
 unsigned char buf[150];
123
 unsigned char pageNr;
124
 unsigned int pagesize;
125
 unsigned char *ptr;
126
} sFlashPage;
127
128
sFlashPage flashPage;

Ich hoff das hilft,

von Uhu U. (uhu)


Lesenswert?

void parser(CANMsg *msg);

steht vor der Definition von CANMsg - das ist alles...
1
# 29 "parser.h" 2
2
3
  void parser(CANMsg *msg);
4
5
  void (*jump_to_app)( void ) ;
6
# 25 "can.h" 2
7
8
# 1 "c:/winavr-20070525/bin/../avr/include/avr/interrupt.h" 1 3
9
# 27 "can.h" 2
10
# 43 "can.h"
11
 typedef struct sCANMsg
12
{
13
    uint16_t id;
14
    uint8_t rtr;
15
    uint8_t length;
16
    uint8_t data[8];
17
} CANMsg;
18
# 21 "can.c" 2

von Andreas K. (a-k)


Lesenswert?

Wirf aus can.h das #include "parser.h" raus.

von Robert S. (razer) Benutzerseite


Lesenswert?

Uhu Uhuhu wrote:
> void parser(CANMsg *msg);
>
> steht vor der Definition von CANMsg - das ist alles...

Andreas Kaiser wrote:
>Und was kann ich dagegen machen?

Hilft nicht

von Uhu U. (uhu)


Lesenswert?

> parser.c
>
> #include "parser.h"

----------

> parser.h:
>
> #ifndef PARSER_H
> #define PARSER_H
>
> #include "boot.h"
> #include "can.h"

-----------

> can.h
>
>  #ifndef CAN_H
>   #define CAN_H
>
>  #include "mcp2515.h"
>  #include "parser.h"

Also:

parser.c zieht parser.h rein
   parser.h zieht can.h rein
      can.h zieht parser.h rein

Damit schaffst du es, daß der Compiler das

   void parser(CANMessage *msg);

vor der Definition von CANMessage sieht.

von Robert S. (razer) Benutzerseite


Lesenswert?

Ok, das ist klar.

Doch was kann ich dagegen machen?

Gruß Robert

von Uhu U. (uhu)


Lesenswert?

Andreas Kaiser wrote:
> Wirf aus can.h das #include "parser.h" raus.

Genau so.

von Robert S. (razer) Benutzerseite


Lesenswert?

Geht leider immer noch nicht.
1
Compiling: can.c
2
avr-gcc -c -mmcu=atmega32 -I. -g   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=can.lst  -std=gnu99 -DF_OSC=16000000  -MD -MP -MF .dep/can.o.d can.c -o can.o 
3
can.c: In function '__vector_1':
4
can.c:164: warning: implicit declaration of function 'parser'
5
6
Compiling: parser.c
7
avr-gcc -c -mmcu=atmega32 -I. -g   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=parser.lst  -std=gnu99 -DF_OSC=16000000  -MD -MP -MF .dep/parser.o.d parser.c -o parser.o 
8
parser.c:43: error: expected ')' before '*' token
9
make.exe: *** [parser.o] Error 1

Gruß Robert

von Uhu U. (uhu)


Lesenswert?

Du hast drei Möglichkeiten:

1. Deine #include-Folgen so zu konstruieren, daß keine Definitionen 
benutzt werden, bevor der Compiler sie gesehen hat

2. Du schreibst die *.c und *.h so um, daß kein Header einen anderen von 
deinen eigenen Header includiert

3. Du schreibst

   void parser(struct sCANMessage *msg);

und verzichtest auf den Effekt des typedef.

Ich würde die zweite Möglichkeit nehmen, weil man sich damit bei 
größeren Projekten diese Art unübersichtlicher Headerprobleme vom Leib 
halten kann.

von Robert S. (razer) Benutzerseite


Lesenswert?

Danke jetzt gehts :)

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.