|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Compiler Help Needed
Ok guys, what is the deal!? I am getting the following errors when I compile:
Code:
OUTPUT MPLINK 3.40, Linker Copyright (c) 2003 Microchip Technology Inc. Error - symbol 'axelWidth' has multiple definitions. Errors : 1 BUILD FAILED: Sat Feb 07 11:04:01 2004 Code:
UserUtilities.h
#ifndef USERUTILITIES_H
#define USERUTILITIES_H
#include "bool.h"
float axelWidth=.725;
float wheelRadius=.105;
int clicksPerRevolution=16;
bool newValue(int *staticVar, int dynamicVar);
float thetaDegrees(int c);
float thetaRadians(int c);
float Forward(int c);
#endif
UserUtilities.c
#ifndef USERUTILITIES_C
#define USERUTILITIES_C
#include "bool.h"
#include "UserUtilities.h"
bool newValue(int *staticVar, int dynamicVar)
{
if (*staticVar==dynamicVar)
{
*staticVar=dynamicVar;
return true;
}
else
{
return false;
}
}
float thetaDegrees(int clicks)
{
extern float axelWidth;
extern float wheelRadius;
clicks*=22.5;
clicks=clicks*wheelRadius;
clicks/=(float)axelWidth;
return clicks; //22.5*(float)wheelRadius*clicks/(float)axelWidth;
}
float thetaRadians(int clicks)
{
extern float axelWidth;
extern float wheelRadius;
clicks*=3.1415926;
clicks=clicks*wheelRadius;
clicks/=8*axelWidth;
return clicks;
}
#endif
WHAT IS GOING ON!?!?!?!?!?!?!?!?!? Clearly, including the file multiple times is prevented by the preprocessor #ifndef, #define, #endif statements, but it is acting like it just disregards those... |
|
#2
|
||||
|
||||
|
Re: Compiler Help Needed
Slow down and look at what you are doing.
You defined axelWidth in userutilities.h and then included userutilities.h in userutilities.c... This means that axelWidth is defined as a float. Now you redefine axelWidth as an external variable in userutilities.c meaning that some OTHER module has defined axelWidth. This is a double declaration and is only the tip of the iceberg... I see a bunch. i.e. you include bool.h multiple times... Also, take a few minutes and see various threads about float variables and implicit initializations... You are going down a very dangerous road. Regards, |
|
#3
|
|||
|
|||
|
Re: Compiler Help Needed
Quote:
Thanx in advance. |
|
#4
|
|||
|
|||
|
Re: Compiler Help Needed
Quote:
Well, the issue with floats is that this micro does not have a Floating Point Unit. So, while on your PC the FPU would quicky preform any math involving floats, that all has to be emulated in software on this micro. That is bad becuase that emulation is fairly complex and could potentially slow down your program considerably, especially if you use alot of floating point numbers. The concerns about the implicit initializations, is basically that normally on microprocessors, the line int i = 5; may not automatically initalize i = 5. Though that is really a moot point in this case since IFI has a routine that does initalize the variables for us. (in ifi_startup.c for those who haven't seen it.) ----------------------- No, you can't use extern with #define. #define isn't actually a variable, what it means, is before the code is complied (in the pre-processor), the any time the first item after the #define is found, it is replaced with the second. So: #define PI 3.1415926538 int C, R = 3; C= 2*PI*R; Becomes (after the pre-processor, but before the actuall compiler) int C, R = 3; C= 2*3.1415926538*R; So if you just put the #define axelWidth .725 in one header file, that you include everywhere, you can use axelWidth with no other effort. ------------------------------ |
|
#5
|
||||
|
||||
|
Re: Compiler Help Needed
As an example, when using a microcontroller, using this:
#define PI (22 / 7) is *considerably* faster than using 3.14159... and it gives a fairly decent approximation. Also, to prevent re-inclusion of header files, people usually do something like this: myheader.h #ifndef MYHEADER_H #define MYHEADER_H .. Entire header file ... #endif /* ifndef MYHEADER_H */ This prevents weird recursion problems from having a header file included twice at the top of a C file. It's sloppy, and I don't recommend doing this, because if you *need* to do this, you're already down the dangerous road they've been speaking of and you ultimately need to fix that or you'll just have a *monstrous* headache at competition when you're rapidly changing code. |
|
#6
|
||||
|
||||
|
Re: Compiler Help Needed
Also, you can completley eliminate floating point from your code.
#define axelWidth 0.725 becomes: #define AXEL_WIDTH_NUM 29 #define AXEL_WIDTH_DEN 40 Constants that are #defined are usually all caps by convention. Also, keep in mind that when using integers, order of operations isn't the same as it is in your math class. Well, it is, but the order of operations will affect the result of the equation. Code:
// Consider: #define NUM 50 #define DEN 100 int foo = NUM / DEN * joy1_y int bar = NUM * joy1_y / DEN Basically, stick to integer math, and multiply to the biggest number you can before starting to divide using integers to prevent always multoplying by zero. Last edited by Jeff McCune : 07-02-2004 at 19:22. |
|
#7
|
|||
|
|||
|
Re: Compiler Help Needed
Quote:
|
|
#8
|
|||
|
|||
|
Re: Compiler Help Needed
Quote:
|
|
#9
|
|||||
|
|||||
|
Re: Compiler Help Needed
Only in integer math (pi rounded down is three).
Ps- My bad on the #declare! |
|
#10
|
|||
|
|||
|
Re: Compiler Help Needed
Quote:
Yes, exactly (22/7) is integer math (22.0/7) would be floating point. [Or ((float)22/7)] |
|
#11
|
||||
|
||||
|
Re: Compiler Help Needed
Quote:
#define PI 3 ![]() |
|
#12
|
||||
|
||||
|
Re: Compiler Help Needed
Quote:
![]() |
|
#13
|
||||
|
||||
|
Re: Compiler Help Needed
Quote:
|
|
#14
|
||||
|
||||
|
Re: Compiler Help Needed
Quote:
#define PI 22 / 7 #define DIAMETER 10 circ = DIAMATER * PI; /* circ = 10 * 22 / 7 */ |
|
#15
|
|||
|
|||
|
Re: Compiler Help Needed
Ok, thanks for the info guys, but my problem still isn't fixed. I still get the error about having multiple definitions, even though I don't. I have included the preprocessor directives #ifndef, #define, #endif to prevent such nonsense from bothering me, but to no avail. I have written several functions that I NEED to make my robot work right, and it is extremely frustrating to have the compiler return errors that are unfounded.
Please help! My code is presented on the previous page, and I don't want to re-post it because it is long... Please check it out and tell me why the function "newValue" keeps coming up as having "multiple definitions"! Thanx in advance!!!!!! |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C compiler for 2004 | Tim Skloss | Technical Discussion | 11 | 05-11-2003 22:02 |
| C compiler for 2004 | Tim Skloss | Robotics Education and Curriculum | 2 | 04-11-2003 16:19 |
| The Grand FIRST team.. programmers and others needed | randomperson | Programming | 0 | 31-05-2003 23:46 |
| Weight needed to tilt bridge... | archiver | 2001 | 4 | 23-06-2002 23:43 |
| Inventor 5.0 help needed | Larry Barello | Inventor | 4 | 27-01-2002 10:54 |