Go Down

Topic: Multiple inclusion of custom library function. (Read 4638 times) previous topic - next topic


I have written a file that takes in a number between -128 and 127 that corresponds with the output of a sensor.  -128 represents -1 and 127 represents 127/128.  The function is supposed to take an arcsine of this and return it.  I am computing the arcsine using a lookup table with -128 = -pi/2 and 127 = 127*pi/256 (slightly less than pi/2).

When I try to make this into a library function I get the following error:

magAcc.cpp.o: In function `arcsineLUTFunc(char)':
c:/arduino-0021/hardware/tools/avr/lib/gcc/../../avr/include/arcsineLUT.h:8: multiple definition of `arcsineLUTFunc(char)'
ADXL345\ADXL345.cpp.o:c:/arduino-0021/hardware/tools/avr/lib/gcc/../../avr/include/arcsineLUT.h:8: first defined here
c:/arduino-0021/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
magAcc.cpp.o:(.data.arcsineLUT1+0x0): multiple definition of `arcsineLUT1'
ADXL345\ADXL345.cpp.o:(.data.arcsineLUT1+0x0): first defined here

The file arcsineLUT.h is

Code: [Select]

#ifndef arcsineLUTFile
#define arcsineLUTFile

#include "WProgram.h"
char arcsineLUT1[256] = {/*lookup table numbers go here*/};
char arcsineLUTFunc(char index)
if(index > 127)
index = 127;
if(index < -128)
index = -128;
return arcsineLUT1[index - -128];

This file is not included anywhere else in my program.

The file that include it is (ADXL345.h)

Code: [Select]

#ifndef ADXL_h
#define ADXL_h

#include "WProgram.h"
#include <Wire.h>
#include <arcsineLUT.h>
// Lots of #defines

class cADXL345
//various different member functions and variables

//various different member functions and variables

#endif // ADXL345_h

The corresponding cpp file is

Code: [Select]

#include "WProgram.h"
#include "ADXL345.h"
//various different member functions that don't use arcsineLUT.h.

//The function that uses arcsineLUT.h stripped of irrelevant code.
void cADXL345::phiTheta()

theta = arcsineLUTFunc((char)(128*x)/xs);
phi    = arcsineLUTFunc((char)(128*y)/ys);



I have solved the problem.

The array and function needed to go into a .cpp file and the function prototype in the .h file.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131