Pages: [1]   Go Down
Author Topic: Strange error.. (multiple definitions)  (Read 861 times)
0 Members and 1 Guest are viewing this topic.
Bonn, Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am currently writing a small library and experience a small problem..
I am including from a existing (working) library one of my headers for configuration which has also a few functions in it (with code). Now all i get at compilation is an error that tells me that i have multiple definitions of this functions. If i put them into a cpp file that corresponds to my header i get a helll lot of errors about almost everything (half of the used core functions are not recognised, so are also byte and int and so on..)
Is there, somewhere, a short description on what to include in libraries and especially what not? From what i see here this has changed over time as core libs have changed and for example wconstants.h seems to be useful yet provokes another set of 100s of errors ><
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/playground/Code/Library#How

Generally:

Library.h
Code:
#ifndef LIBRARY_H
#define LIBRARY_H

#include<WProgram.h>

class Library {
  //code
};

#endif

Library.cpp
Code:
#include "Library.h"
//code
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried exactly that as well.. now i come accross:

Code:
In file included from C:\arduino-0015\hardware\cores\arduino/WProgram.h:4,
                 from /ks0108_PCF8574.h:12,
                 from /ks0108.h:47,
                 from ks0108.cpp:37:
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'
In file included from C:\arduino-0015\hardware\cores\arduino/WProgram.h:6,
                 from /ks0108_PCF8574.h:12,
                 from /ks0108.h:47,
                 from ks0108.cpp:37:
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
c:/arduino-0015/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
o: In function `drawSpinner(unsigned char, unsigned char, unsigned char)':

*edit*
I think there is such a #undef thing for that problem, yet thanks to the search engine on this forum and my lack of knowleadge on using google prevents me from finding an answer... also there should be some nicer solution i hope?
« Last Edit: July 02, 2009, 04:27:44 am by Nachtwind » Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Bonn, Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

After doing several #undef parts i now am back at where i began:

Code:
o: In function `getTWIDATA(int)':
C:\arduino-0015/hardware\libraries\ks0108/ks0108_PCF8574.h:62: multiple definition of `getTWIDATA(int)'

hardware\libraries\ks0108\ks0108.o:/ks0108_PCF8574.h:62: first defined here

o: In function `setCommandTWI(unsigned char)':
C:\arduino-0015/hardware\libraries\ks0108/ks0108_PCF8574.h:54: multiple definition of `setCommandTWI(unsigned char)'

hardware\libraries\ks0108\ks0108.o:/ks0108_PCF8574.h:54: first defined here

o: In function `writeCommandTWI(int, int)':
C:\arduino-0015/hardware\libraries\ks0108/ks0108_PCF8574.h:72: multiple definition of `writeCommandTWI(int, int)'

hardware\libraries\ks0108\ks0108.o:/ks0108_PCF8574.h:72: first defined here

o: In function `setDataTWI(unsigned char)':
C:\arduino-0015/hardware\libraries\ks0108/ks0108_PCF8574.h:47: multiple definition of `setDataTWI(unsigned char)'

hardware\libraries\ks0108\ks0108.o:/ks0108_PCF8574.h:47: first defined here

Couldn't determine program size: C:\arduino-0015\hardware\tools\avr\bin\avr-size: 'C:\Users\NACHTW~1\AppData\Local\Temp\build40589.tmp\KS0108_fertigcode.hex': No such file


*edit*
I have, definetely only defined the functions once inside the file of which the name is given - yet i must admit i have not only giving the name and the params but all code of the function in the header.. might that be some problem?
« Last Edit: July 02, 2009, 04:41:01 pm by Nachtwind » Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

0
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am including from a existing (working) library one of my headers for configuration which has also a few functions in it (with code). Now all i get at compilation is an error that tells me that i have multiple definitions of this functions.

So you have an existing library with functions in it, and you're trying to include it in a new library with functions that have the same names?
Logged

Bonn, Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No there is a library (namely the ks0108 lib you can find almost on top of the software development forum) and this library includes a configguration file based on a definition you have to make in one of the first few lines.
So i made a new file to be included which is almost the same as any other, yet only that it has 4 functions inside (in the H file) which are told to be be defined multiple times. thats all. so its like

PDE includes s0108 lib
 includes Configuration
 main configuration includes Arduino Config or Mega Config or Sanguino Config or My Header

and there lies the problem ;0)
  
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Bonn, Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...and it is getting even more weird:

Code:
In file included from ks0108_PCF8574.c:2:
hardware\libraries\Wire/Wire.h:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'TwoWire'
hardware\libraries\Wire/Wire.h:64: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Wire'
Logged

Believe me, Mike, I calculated the odds of this succeeding against the odds I was doing something incredibly stupid[ch8230] and I went ahead

Pages: [1]   Go Up
Jump to: