Forum: Compiler & IDEs wieder einmal "undifined reference"


von Josef K. (zumlin)


Lesenswert?

Hallo zusammen.
Ich weiß jetzt schon, dass es mein Fehelr ist, aber ich finde ihn 
einfach nicht. Ich versuche hier mal alles wichtige zu posten. Also:

Ich bekomme folgende Fehlermeldung:
../main.c:321: undefined reference to `_crc16_update'

in Zeile 321 steht jedoch:
320  ISR(USART0_TX_vect) //Transmit Routine
321  {
323  if ((tx_index >= BUFFER_SIZE) || (tx_index >= tx_buffer[PKT_LEN]))

...nichts
Schon mal komisch. Also suche in main.c die Funktion "_crc16_update". 
Das bringt mich zu Zeile 181:
crc = _crc16_update(crc, rx_buffer[i]);

Die Funktion kommt aus der util/crc16.h
Diese wird etwas komisch in mein Programm eingebunden. main.c bindet
#include "bus.h" ein.
bus.c bindet
#include <avr/crc16.h> ein.
avr/crc16.h sieht so aus:
1
/* $Id: crc16.h,v 1.10 2005/11/05 22:23:15 joerg_wunsch Exp $ */
2
3
#ifndef _AVR_CRC16_H_
4
#define _AVR_CRC16_H_
5
6
#include <util/crc16.h>
7
8
9
#endif /* _AVR_CRC16_H_ */

die util/crc16.h sieht so aus:
1
/* $Id: crc16.h,v 1.2.2.1 2006/04/19 20:35:54 joerg_wunsch Exp $ */
2
3
#ifndef _UTIL_CRC16_H_
4
#define _UTIL_CRC16_H_
5
6
#include <stdint.h>
7
8
/** \defgroup util_crc <util/crc16.h>: CRC Computations
9
    \code#include <util/crc16.h>\endcode
10
11
    This header file provides a optimized inline functions for calculating
12
    cyclic redundancy checks (CRC) using common polynomials.
13
14
    \par References:
15
16
    \par
17
18
    See the Dallas Semiconductor app note 27 for 8051 assembler example and
19
    general CRC optimization suggestions. The table on the last page of the
20
    app note is the key to understanding these implementations.
21
22
    \par
23
24
    Jack Crenshaw's "Implementing CRCs" article in the January 1992 isue of \e
25
    Embedded \e Systems \e Programming. This may be difficult to find, but it
26
    explains CRC's in very clear and concise terms. Well worth the effort to
27
    obtain a copy.
28
29
    A typical application would look like:
30
31
    \code
32
    // Dallas iButton test vector.
33
    uint8_t serno[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0, 0xa2 };
34
35
    int
36
    checkcrc(void)
37
    {
38
  uint8_t crc = 0, i;
39
40
  for (i = 0; i < sizeof serno / sizeof serno[0]; i++)
41
      crc = _crc_ibutton_update(crc, serno[i]);
42
43
  return crc; // must be 0
44
    }
45
    \endcode
46
*/
47
48
/** \ingroup util_crc
49
    Optimized CRC-16 calculation.
50
51
    Polynomial: x^16 + x^15 + x^2 + 1 (0xa001)<br>
52
    Initial value: 0xffff
53
54
    This CRC is normally used in disk-drive controllers.
55
56
    The following is the equivalent functionality written in C.
57
58
    \code
59
    uint16_t
60
    crc16_update(uint16_t crc, uint8_t a)
61
    {
62
  int i;
63
64
  crc ^= a;
65
  for (i = 0; i < 8; ++i)
66
  {
67
      if (crc & 1)
68
    crc = (crc >> 1) ^ 0xA001;
69
      else
70
    crc = (crc >> 1);
71
  }
72
73
  return crc;
74
    }
75
76
    \endcode */
77
78
static __inline__ uint16_t
79
_crc16_update(uint16_t crc, uint8_t a)
80
{
81
82
  int i;
83
84
  crc ^= a;
85
  for( i = 0; i < 8; ++i )
86
  {
87
      if( crc & 1 )
88
    crc = (crc>>1) ^ 0xA001;
89
      else
90
    crc = (crc>>1);
91
  }
92
93
  return crc;
94
}
95
96
/** \ingroup util_crc
97
    Optimized CRC-XMODEM calculation.
98
99
    Polynomial: x^16 + x^12 + x^5 + 1 (0x1021)<br>
100
    Initial value: 0x0
101
102
    This is the CRC used by the Xmodem-CRC protocol.
103
104
    The following is the equivalent functionality written in C.
105
106
    \code
107
    uint16_t
108
    crc_xmodem_update (uint16_t crc, uint8_t data)
109
    {
110
        int i;
111
112
        crc = crc ^ ((uint16_t)data << 8);
113
        for (i=0; i<8; i++)
114
        {
115
            if (crc & 0x8000)
116
                crc = (crc << 1) ^ 0x1021;
117
            else
118
                crc <<= 1;
119
        }
120
121
        return crc;
122
    }
123
    \endcode */
124
125
static __inline__ uint16_t
126
_crc_xmodem_update(uint16_t __crc, uint8_t __data)
127
{
128
    uint16_t __ret;             /* %B0:%A0 (alias for __crc) */
129
    uint8_t __tmp1;             /* %1 */
130
    uint8_t __tmp2;             /* %2 */
131
                                /* %3  __data */
132
133
    __asm__ __volatile__ (
134
        "eor    %B0,%3"          "\n\t" /* crc.hi ^ data */
135
        "mov    __tmp_reg__,%B0" "\n\t"
136
        "swap   __tmp_reg__"     "\n\t" /* swap(crc.hi ^ data) */
137
138
        /* Calculate the ret.lo of the CRC. */
139
        "mov    %1,__tmp_reg__"  "\n\t"
140
        "andi   %1,0x0f"         "\n\t"
141
        "eor    %1,%B0"          "\n\t"
142
        "mov    %2,%B0"          "\n\t"
143
        "eor    %2,__tmp_reg__"  "\n\t"
144
        "lsl    %2"              "\n\t"
145
        "andi   %2,0xe0"         "\n\t"
146
        "eor    %1,%2"           "\n\t" /* __tmp1 is now ret.lo. */
147
148
        /* Calculate the ret.hi of the CRC. */
149
        "mov    %2,__tmp_reg__"  "\n\t"
150
        "eor    %2,%B0"          "\n\t"
151
        "andi   %2,0xf0"         "\n\t"
152
        "lsr    %2"              "\n\t"
153
        "mov    __tmp_reg__,%B0" "\n\t"
154
        "lsl    __tmp_reg__"     "\n\t"
155
        "rol    %2"              "\n\t"
156
        "lsr    %B0"             "\n\t"
157
        "lsr    %B0"             "\n\t"
158
        "lsr    %B0"             "\n\t"
159
        "andi   %B0,0x1f"        "\n\t"
160
        "eor    %B0,%2"          "\n\t"
161
        "eor    %B0,%A0"         "\n\t" /* ret.hi is now ready. */
162
        "mov    %A0,%1"          "\n\t" /* ret.lo is now ready. */
163
        : "=d" (__ret), "=d" (__tmp1), "=d" (__tmp2)
164
        : "r" (__data), "0" (__crc)
165
        : "r0"
166
    );
167
    return __ret;
168
}
169
170
/** \ingroup util_crc
171
    Optimized CRC-CCITT calculation.
172
173
    Polynomial: x^16 + x^12 + x^5 + 1 (0x8408)<br>
174
    Initial value: 0xffff
175
176
    This is the CRC used by PPP and IrDA.
177
178
    See RFC1171 (PPP protocol) and IrDA IrLAP 1.1
179
180
    \note Although the CCITT polynomial is the same as that used by the Xmodem
181
    protocol, they are quite different. The difference is in how the bits are
182
    shifted through the alorgithm. Xmodem shifts the MSB of the CRC and the
183
    input first, while CCITT shifts the LSB of the CRC and the input first.
184
185
    The following is the equivalent functionality written in C.
186
187
    \code
188
    uint16_t
189
    crc_ccitt_update (uint16_t crc, uint8_t data)
190
    {
191
        data ^= lo8 (crc);
192
        data ^= data << 4;
193
194
        return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4) 
195
                ^ ((uint16_t)data << 3));
196
    }
197
    \endcode */
198
199
static __inline__ uint16_t
200
_crc_ccitt_update (uint16_t __crc, uint8_t __data)
201
{
202
    uint16_t __ret;
203
204
    __asm__ __volatile__ (
205
        "eor    %A0,%1"          "\n\t"
206
207
        "mov    __tmp_reg__,%A0" "\n\t"
208
        "swap   %A0"             "\n\t"
209
        "andi   %A0,0xf0"        "\n\t"
210
        "eor    %A0,__tmp_reg__" "\n\t"
211
212
        "mov    __tmp_reg__,%B0" "\n\t"
213
214
        "mov    %B0,%A0"         "\n\t"
215
216
        "swap   %A0"             "\n\t"
217
        "andi   %A0,0x0f"        "\n\t"
218
        "eor    __tmp_reg__,%A0" "\n\t"
219
220
        "lsr    %A0"             "\n\t"
221
        "eor    %B0,%A0"         "\n\t"
222
223
        "eor    %A0,%B0"         "\n\t"
224
        "lsl    %A0"             "\n\t"
225
        "lsl    %A0"             "\n\t"
226
        "lsl    %A0"             "\n\t"
227
        "eor    %A0,__tmp_reg__"
228
229
        : "=d" (__ret)
230
        : "r" (__data), "0" (__crc)
231
        : "r0"
232
    );
233
    return __ret;
234
}
235
236
/** \ingroup util_crc
237
    Optimized Dallas (now Maxim) iButton 8-bit CRC calculation.
238
239
    Polynomial: x^8 + x^5 + x^4 + 1 (0x8C)<br>
240
    Initial value: 0x0
241
242
    See http://www.maxim-ic.com/appnotes.cfm/appnote_number/27
243
244
    The following is the equivalent functionality written in C.
245
246
    \code
247
    uint8_t
248
    _crc_ibutton_update(uint8_t crc, uint8_t data)
249
    {
250
  uint8_t i;
251
252
  crc = crc ^ data;
253
  for (i = 0; i < 8; i++)
254
  {
255
      if (crc & 0x01)
256
          crc = (crc >> 1) ^ 0x8C;
257
      else
258
          crc >>= 1;
259
  }
260
261
  return crc;
262
    }
263
    \endcode
264
*/
265
266
static __inline__ uint8_t
267
_crc_ibutton_update(uint8_t __crc, uint8_t __data)
268
{
269
  uint8_t __i, __pattern;
270
  __asm__ __volatile__ (
271
    "  eor  %0, %4" "\n\t"
272
    "  ldi  %1, 8" "\n\t"
273
    "  ldi  %2, 0x8C" "\n\t"
274
    "1:  bst  %0, 0" "\n\t"
275
    "  lsr  %0" "\n\t"
276
    "  brtc  2f" "\n\t"
277
    "  eor  %0, %2" "\n\t"
278
    "2:  dec  %1" "\n\t"
279
    "  brne  1b" "\n\t"
280
    : "=r" (__crc), "=d" (__i), "=d" (__pattern)
281
    : "0" (__crc), "r" (__data));
282
  return __crc;
283
}
284
285
#endif /* _UTIL_CRC16_H_ */

Wo leigt der Fehler? Ist alles zwar etwas  verschachtelt, weil ich das 
meiste nicht selber geschrieben habe, aber funktionieren sollte das 
meiner Meinung nach schon. Meine Meinung ist aber offensichtlich falsch 
:)
Wo liegt mein Fehler?

von Karl H. (kbuchegg)


Lesenswert?

Ist das ein Tippfehler:

> #include "bus.h" ein.
> bus.c bindet
> #include <avr/crc16.h> ein.

Hast du wirklich ein bus.c  oder sollte das in der mittleren
Zeile bus.h heissen?


Solch verzwickten Header-Schachtelfehler komme ich sehr oft
mit folgender Strategie auf die Schliche:

Ich baue gezielt einen Fehler in ein Header File ein und sehe
nach, ob der Compiler den auch wirklich meldet.

zb.:
Würde ich mal in bus.h einen Fehler einbauen. Einfach
irgendwas in der Form
1
...
2
xyzui
3
#include <avr/crc16.h>
4
...

Kommt der Fehler, dann weis ich, dass diese Codestelle auch wirklich
eingebunden wurde und nicht durch irgendwelche #ifdef oder dgl.
rausgefallen ist. Kommt er nicht, dann verschiebe ich den Fehler
nach vorne bzw. ausserhalb des Header Files, bis ich ihn sehe.
Siehst du den Fehler im Compiler, dann wuerde ich ihn mal in die
crc16.h heineinverschieben und dann geht das Spielchen von vorne
los.

Und so taste ich mich an die Codestelle ran, die dafür sorgt
dass ein Header aus irgendeinem Grund nicht eingebunden wird.
Das ganze Vorgehen klingt sehr primitiv. Ist es auch. Geht aber
in der Praxis sehr schnell.

von Josef K. (zumlin)


Lesenswert?

Verdammt. Danke. :)
Das war der Fehler.

Jetzt bekomm ich aber
gcc plug-in: Error: Object file not found on expected location 
C:\AVR\RS485\default\rs485.elf

Hier mal die "Build" Ausgabe. Alles darin ist leider nicht auf meinem 
Mist gewachsen. :)
1
Build started 24.11.2007 at 18:46:49
2
avr-gcc.exe -mmcu=atmega128 -Wl,-Map=rs485.map bus.o main.o uart0.o   -L"C:\Programme\AVRlib"  -lm -lc  -o rs485.elf
3
main.o: In function `ArbBitSend':
4
../bus.c:29: multiple definition of `priority'
5
bus.o:../bus.c:29: first defined here
6
main.o: In function `ArbBitSend':
7
../bus.c:29: multiple definition of `loneliness'
8
bus.o:../bus.c:29: first defined here
9
main.o: In function `ArbBitSend':
10
../bus.c:29: multiple definition of `mrbus_activity'
11
bus.o:../bus.c:29: first defined here
12
main.o: In function `ArbBitSend':
13
../bus.c:29: multiple definition of `rx_index'
14
bus.o:../bus.c:29: first defined here
15
main.o: In function `ArbBitSend':
16
../bus.c:31: multiple definition of `tx_index'
17
bus.o:../bus.c:31: first defined here
18
main.o: In function `ArbBitSend':
19
../bus.c:29: multiple definition of `ArbBitSend'
20
bus.o:../bus.c:29: first defined here
21
main.o: In function `xmit_packet':
22
../bus.c:66: multiple definition of `xmit_packet'
23
bus.o:../bus.c:66: first defined here
24
make: *** [rs485.elf] Error 1
25
Build succeeded with 0 Warnings...

von Karl H. (kbuchegg)


Lesenswert?

Tja. Das wirst du wohl korrigieren müssen.

von Karl H. (kbuchegg)


Lesenswert?

Josef Kkk wrote:
> Verdammt. Danke. :)
> Das war der Fehler.

Was. Das mit dem bus.c/bus.h?

Du wirst doch nicht. Oder doch?
Du hast da aber jetzt nicht wirklich ein
#include "bus.c"
daraus gemacht?

http://www.mikrocontroller.net/articles/FAQ#Ich_hab_da_mehrere_.2A.c_und_.2A.h_Dateien._Was_mache_ich_damit.3F

von Josef K. (zumlin)


Lesenswert?

:)
Nur wie? Ich flipp noch aus mit dem Zeugs.
in bus.c wird keine der Variablen erzeugt die werden ja in der bus.h 
erzeugt, und die scahut soweit ganz gut aus.

hier mal die bus.h
1
#ifndef BUS_H
2
#define BUS_H
3
4
#define BUFFER_SIZE  0x14   // 20 bytes
5
6
#define UART_BAUD_RATE      9600    
7
#define UART_BAUD_SELECT (F_CPU/(UART_BAUD_RATE*16l)-1)
8
9
// AVR type-specific stuff
10
11
12
#define RS485PORT PORTE
13
#define RS485DDR DDRE
14
#define RS485TXEN 2 //(=PE2)
15
#define TX 1
16
#define RX 0
17
#define SER_CONT_REG UCSR0B
18
#define SER_STAT_REG UCSR0A
19
#define UART_RXMASK 0x01   // ??
20
#define UARTPORT PINE    // ?? 
21
#define RC_ERR_MASK 0x0C  // ??
22
#define CHR9 UCSZ2
23
#define OR DOR
24
#define UBRR UBRRL
25
#define UDR UDR0
26
27
28
29
30
/* Packet component defines */
31
#define PKT_SRC   0
32
#define PKT_DEST  1
33
#define PKT_LEN   2
34
#define PKT_CRC_L 3
35
#define PKT_CRC_H 4
36
#define PKT_TYPE  5
37
38
39
// for programming CVs
40
#define PKT_CV 6
41
#define PKT_VALUE 7
42
43
44
/* Status Masks */
45
#define RX_PKT_READY 0x01
46
#define TX_PKT_READY 0x80
47
#define TX_BUF_ACTIVE 0x20
48
49
50
/*timing defines for 16MHz
51
#define __10_MS 0x9C
52
#define __20_US 0x28
53
#define __2_MS 0x1E
54
#define __10_US 0x14
55
#define __100_US 0xC8
56
*/
57
58
//general timig defines
59
#define __10_MS (10*(F_CPU/1024)/1000)
60
#define __2_MS (2*(F_CPU/1024)/1000)
61
#define __20_US (20*(F_CPU/8)/1000000)
62
#define __10_US (10*(F_CPU/8)/1000000)
63
#define __100_US (100*(F_CPU/8)/1000000)
64
65
unsigned char dev_addr;
66
unsigned short crc16_value;
67
68
unsigned char rx_buffer[BUFFER_SIZE];
69
unsigned char rx_input_buffer[BUFFER_SIZE];
70
unsigned char tx_buffer[BUFFER_SIZE];
71
unsigned char tx_index=0;
72
unsigned char rx_index=0;
73
unsigned char state;
74
unsigned char mrbus_activity=0;
75
unsigned char loneliness=6;
76
unsigned char priority=6;
77
78
unsigned char ArbBitSend(unsigned char bit);
79
unsigned char xmit_packet(void);
80
81
82
#endif

und hier auch noch die bus.c wenn ich eh schon so viel zeugs sinnlos 
poste :(
1
#include "bus.h"
2
#include <avr/io.h>
3
#include <stdlib.h>
4
#include <stdint.h>
5
#include "global.h"
6
#include <avr/interrupt.h>
7
#include <avr/crc16.h>
8
9
10
unsigned char ArbBitSend(unsigned char bit)
11
{
12
  char slice;
13
  char tmp=0;
14
15
  if (bit)
16
  {
17
    //TX is already 0 (mark)
18
    cbi(RS485PORT, RS485TXEN);
19
  } else {
20
    sbi(RS485PORT, RS485TXEN);
21
  }
22
23
  for (slice=0; slice<10; slice++)
24
  {
25
    if (slice > 2)
26
    {
27
      if (UARTPORT & UART_RXMASK) tmp=1;
28
      if (tmp ^ bit)
29
      {
30
        cbi(RS485PORT, RS485TXEN);
31
        sbi(SER_CONT_REG, RXEN);
32
        sbi(SER_CONT_REG, RXCIE);
33
        sei();
34
        return(1);
35
      }
36
      
37
    }
38
    // delay_us(20);
39
    TCNT0 = 0x00;
40
    while (TCNT0 < __20_US);
41
  }
42
43
  return(0);
44
}
45
46
47
unsigned char xmit_packet(void)
48
{
49
  unsigned char status;
50
  unsigned char address;
51
  unsigned char i;
52
  
53
  address = tx_buffer[PKT_SRC];
54
  
55
  if (state & TX_BUF_ACTIVE) return(1);
56
  cbi(SER_CONT_REG, UDRIE);
57
  
58
  // First calculate CRC16
59
  crc16_value=0x0000;
60
  
61
  for(i=0;i<tx_buffer[PKT_LEN];i++)
62
  {
63
    if ((i != PKT_CRC_H) && (i != PKT_CRC_L))
64
    {
65
      crc16_value = _crc16_update(crc16_value, tx_buffer[i]);
66
    }
67
  }
68
  tx_buffer[PKT_CRC_L] = crc16_value & 0xFF;
69
  tx_buffer[PKT_CRC_H] = crc16_value >> 8;  
70
    
71
  mrbus_activity=0;
72
  
73
  /* Begin of arbitration sequence */
74
  TCNT1H = 0x00;
75
  TCNT1L = 0x00;  
76
  while (TCNT1L < __2_MS);
77
  
78
  if (mrbus_activity) return(1);
79
  
80
  status = ((loneliness+priority)*10) + (address & 0x0F); 
81
  
82
  RS485PORT&= ~((1 << 0) | (1 << 1) | (1 << 2));      // ersetzt 0x00;
83
  // Clear driver enable
84
  // set xmit pin low
85
  
86
  cbi(RS485DDR, RX); // Set as input
87
  
88
  cbi(SER_CONT_REG, TXEN);
89
  cbi(SER_CONT_REG, RXEN);  // Serial Port disable
90
  
91
  
92
  for (i=0; i<20; i++)
93
  {
94
    // delay_us(20);
95
    TCNT0 = 0x00;
96
    while(TCNT0 < __20_US);
97
    if (0 == (UARTPORT & UART_RXMASK))
98
    {
99
      sbi(SER_CONT_REG, RXEN);
100
      sbi(SER_CONT_REG, RXCIE);
101
      sei();
102
      return(1);
103
    }
104
  }
105
106
  /* Now, wait calculated time from above */
107
  for (i=0; i<status; i++)
108
  {
109
    // delay_us(10);
110
    TCNT0 = 0x00;
111
    while(TCNT0 < __10_US);
112
    if (0 == (UARTPORT & UART_RXMASK))
113
    {
114
      sbi(SER_CONT_REG, RXEN);
115
      sbi(SER_CONT_REG, RXCIE);
116
      sei();
117
      return(1);
118
    }
119
  }
120
  
121
  /* Arbitration Sequence - 4800 bps */
122
  /* Start Bit */
123
  if (ArbBitSend(0)) return(1);
124
125
  for (i=0; i<8; i++)
126
  {
127
    status = ArbBitSend(address & 0x01);
128
    address = address >> 1;
129
130
    if (status == 1) return(1);
131
  }  
132
133
  /* Stop Bits */
134
  if (ArbBitSend(1)) return(1);
135
  if (ArbBitSend(1)) return(1);
136
137
  sbi(SER_CONT_REG, RXEN);
138
  sbi(SER_CONT_REG, TXEN);
139
  sbi(RS485PORT, RS485TXEN);
140
  
141
  tx_index=0;
142
  
143
  return(0); // Control over bus is assumed
144
}

von Marco S (Gast)


Lesenswert?

Wenn main.c und bus.c die bus.h einbinden, sieht die bus.h nicht so gut 
aus. Du musst schon dafür sorgen, dass die Variablendefinition nicht 
mehrfach vorgenommen wird. Z.B.

--bus.h---
1
#include <inttypes.h>
2
#ifdef BUS_MODULE
3
  uint32_t xyz;
4
#else
5
  extern uint32_t xyz;
6
#endif

--bus.c---
1
#define BUS_MODULE
2
#include "bus.h"


--main.c---
1
#include "bus.h"

von Josef K. (zumlin)


Lesenswert?

main.c bindet aber die bus.c ein nicht bus.h.
Sollte das nicht dann funktionieren?

PS: schön langsam glaub ich steige ich auf ein einfacheres Protokoll für 
rs485 um. :)

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


Lesenswert?

Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.
Man soll keine C-Dateien in C-Dateien includen.

Genügt das?

Du sollst <util/crc16.h> in main.c includen (oder ein Headerfile,
was diese Datei bereits included).  Wenn du in main.c die Funktion
_crc16_ccitt_update() benutzt, musst du sie auch deklariert (und
im vorliegenden Falle infolge des Inlining sogar definiert) haben.

von Josef K. (zumlin)


Lesenswert?

Ok. Hab ich gemacht. Das Problem mit dem neu definieren von Variablen 
hab ich aber noch immer.

wenn ich also in main.c und bus.c die bus.h einfügen will, würde ich, um 
eine redefinitinon zu vermeiden folgendes machen.

bus.h:

#ifndef _BUS_H
#define _BUS_H

#define F_CPU 1234567890
#endif

Also so wie ich das oben auch versucht habe. Leider bekomme ich aber 
immer noch die Fehlermedlungen wie oben gepostet. Was geth da schief?

von Oliver (Gast)


Lesenswert?

In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.
In eine .h-Datei gehört keine Varaiblen-Deklaration.


in bla.h gehört:
extern int var1;

in bla.c gehört
int var1;

#define F_CPU gehört entweder in main.c nach GANZ oben, oder besser noch 
per -DF_CPU xxxxxx in die Compilerflags.

Oliver

von Oliver (Gast)


Lesenswert?

aiaiaiaiai

VARIABLE :-)

Oliver

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


Lesenswert?

Oliver wrote:
> In eine .h-Datei gehört keine Varaiblen-Deklaration.

s/Deklaration/Definition/g

Ansonsten: Zustimmung.

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.