Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   ERROR (http://www.chiefdelphi.com/forums/showthread.php?t=35526)

amateurrobotguy 26-02-2005 14:27

ERROR
 
I define like this

void Default_Routine(void)
{
long reduction;
double para;
long nodecimalpara;
long reduction2;
double para2;
long nodecimalpara2;

and get this:

D:\Robot\MyFiles\user_routines.c:239:Error [1105] symbol 'redeuction' has not been defined
D:\Robot\MyFiles\user_routines.c:246:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:247:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:252:Error [1105] symbol 'redeuction2' has not been defined
D:\Robot\MyFiles\user_routines.c:259:Error [1139] integer types required for bitwise XOR operator
D:\Robot\MyFiles\user_routines.c:260:Warning [2058] call of function without prototype

Alex1072 26-02-2005 14:29

Re: ERROR
 
There's nothing that I can see in your code that should be causing those errors. It would help if you posted the rest of the function.

EDIT: After looking at it again, it looks like you spelled reduction differently from how you declared it:

D:\Robot\MyFiles\user_routines.c:239:Error [1105] symbol 'redeuction' has not been defined

The symbol 'redeuction' has not been defined, only 'reduction' has been.

Also, for this error:
D:\Robot\MyFiles\user_routines.c:259:Error [1139] integer types required for bitwise XOR operator

the 'a^b' in C/C++/java is not actually a to the power of b. It's the XOR operator.

if you have two binary integers: a = 1011, b= 1101, a^b would be: 0110. XOR compares each binay digit of a with the corresponding digit of b. If the digits are different, a 1 is placed as the corresponding digit of the result, if they are the same, a 0 is placed.

If you need to do something like a^2, you should just do a*a. If you need actual exponentials then you have to use math.h or write your own function. If you use the c math library, pow(a, b) = a to the bth power.

EDIT #2: fixed the name of the power function

amateurrobotguy 26-02-2005 14:36

Re: ERROR
 
Ok, I will post my function...but where you see ???? it means the number has been editied out for secrecy purposes. BTW with the spelling fixed I still get :
D:\Robot\MyFiles\user_routines.c:242:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:243:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:255:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:256:Error [1105] symbol 'nodecimalparatwo' has not been defined
D:\Robot\MyFiles\user_routines.c:256:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:256:Error [1101] lvalue required
D:\Robot\MyFiles\user_routines.c:257:Error [1105] symbol 'nodecimalparatwo' has not been defined

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
#include "user_Serialdrv.h"
#include <math.h>

...
void Default_Routine(void)
{
long reduction, nodecimalpara, reductiontwo, nodecomal, paratwo;
double para, para2;

/*---------- Analog Inputs (Joysticks) to PWM Outputs-----------------------
*--------------------------------------------------------------------------
* This maps the joystick axes to specific PWM outputs.
*/
reduction=p1_y-?;
if (reduction>=0)
{
}
else
{
reduction=reduction*-1;
}
para=((pow(reduction, ?)/?)+?);
nodecimalpara=ceil(para);
pwm01 = nodecimalpara;


reductiontwo=p2_y-?;
if (reductiontwo<=0)
{
reductiontwo=reductiontwo*-1;
}
else
{
}
paratwo=((pow(reductiontwo, ?/?)+?);
nodecimalparatwo=ceil(paratwo);
pwm02 = nodecimalparatwo;

Alex1072 26-02-2005 14:55

Re: ERROR
 
D:\Robot\MyFiles\user_routines.c:242:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:243:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:255:Error [1139] integer types required for bitwise XOR operator
D:\Robot\MyFiles\user_routines.c:256:Error [1105] symbol 'nodecimalparatwo' has not been defined
D:\Robot\MyFiles\user_routines.c:256:Warning [2058] call of function without prototype
D:\Robot\MyFiles\user_routines.c:256:Error [1101] lvalue required
D:\Robot\MyFiles\user_routines.c:257:Error [1105] symbol 'nodecimalparatwo' has not been defined

If you look at the numbers after the name of the file: 243, 243, 255, 256, etc. The compiler tells you on which line the error is happening. Since I don't know the exact line numbers i'm not sure if this is the actual cause of the errors, but:

nodecimalparatwo is not defined, you should look at the variable declaration at the top of your function and make sure you don't use any variables that you do not declare.

The 'call of function without declaration' errors are happening because of the pow and ceil functions. These functions are provided in math.h, and are the correct names (http://www.opengroup.org/onlinepubs/...sh/math.h.html), but in order to use them you have to let the compiler know that you're going to be using the math.h library. In order to do that you have to put this line at the top of your file next to the other similar ones:
Code:

#include <math.h>
This will tell the compiler about all the functions that are in the math.h library so that it knows that they exist. The #include command tells the compiler to process the file "math.h" as if it were pasted into the begining of your file. The math.h file has all the declarations that the default c math library needs in order to work, including declarations of the pow and ceil functions you are trying to use.

amateurrobotguy 26-02-2005 15:01

Re: ERROR
 
Ok, I fixed my definitions, but I am still getting the w/o prototype error. I did put the math.h here: It gives me the errors, then compiles further, but gives me build failed.

/************************************************** *****************************
* FILE NAME: user_routines.c <FRC VERSION>
*
* DESCRIPTION:
* This file contains the default mappings of inputs
* (like switches, joysticks, and buttons) to outputs on the RC.
*
* USAGE:
* You can either modify this file to fit your needs, or remove it from your
* project and replace it with a modified copy.
*
************************************************** *****************************/

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
#include "user_Serialdrv.h"
#include <math.h>

amateurrobotguy 26-02-2005 15:14

Re: ERROR
 
1 Attachment(s)
I think my math.h file might be bad. See the attachment with it. It doesn't have anything in it.

Alex1072 26-02-2005 15:18

Re: ERROR
 
I've never actually used math.h in MPLAB, so I can't really say much. My math.h file is exactly the same though. For ceiling you could easilly write your own function; power is harder if you want it to support non-integer exponents. Anyone else have any suggestions? Is there a way to use math.h in mplab?

amateurrobotguy 26-02-2005 15:19

Re: ERROR
 
Anyone have a good copy of math.h with all the math functions?

Kevin Sevcik 26-02-2005 16:23

Re: ERROR
 
math.h is just a header file. header files typically don't contain any code, they just have compiler directives in case that library needs other includes, etc. The actual code will be in a math.c file in a libraries folder or something. I'm afraid I can't tell you for certain because I'm not at a computer with the compiler at the moment. At any rate, either you're missing math.c or it's corrupted, or someone's fiddled with compiler settings and you aren't pointing the compiler to the proper library folder anymore.

EDIT:
From a brief perusal, I note that the include folder should be c:\mcc18\lib

amateurrobotguy 26-02-2005 17:08

Re: ERROR
 
First, if the include isn't set to the /h section, it will error with no adc.h found.
Can anyone explain the procedure for getting ceil() and pow() to work. I don't mind if its a header or a c file or manually program it in.

amateurrobotguy 26-02-2005 17:26

Re: ERROR
 
I have made some progress. I got rid of all the error right down to the last lines:
MPLINK 3.40, Linker
Copyright (c) 2003 Microchip Technology Inc.
Error - could not find definition of symbol 'ceil' in file 'D:\Robot\MyFiles\user_routines.o'.
Errors : 1

All i did was this:

/************************************************** *****************************
* FILE NAME: user_routines.c <FRC VERSION>
*
* DESCRIPTION:
* This file contains the default mappings of inputs
* (like switches, joysticks, and buttons) to outputs on the RC.
*
* USAGE:
* You can either modify this file to fit your needs, or remove it from your
* project and replace it with a modified copy.
*
************************************************** *****************************/

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
#include "user_Serialdrv.h"
#include <math.h>

extern unsigned char aBreakerWasTripped;

/*** DEFINE USER VARIABLES AND INITIALIZE tHEM HERE ***/

/* EXAMPLES: (see MPLAB C18 User's Guide, p.9 for all types)
unsigned char wheel_revolutions = 0; (can vary from 0 to 255)
unsigned int delay_count = 7; (can vary from 0 to 65,535)
int angle_deviation = 142; (can vary from -32,768 to 32,767)
unsigned long very_big_counter = 0; (can vary from 0 to 4,294,967,295)
*/
double ceil(double x);
double pow(double x, double y);

See two last lines. Am I going down the right path? If so, what is causing the error then?

Kevin Sevcik 26-02-2005 17:36

Re: ERROR
 
the new error is because ceil and pow aren't really defined as anything, I'm sure.

and my mistake, it's been a while since I've really programmed. I meant the library path should be set to c:\mcc18\lib and look in that folder and make sure there's a math.c file and it has the proper functions.

Alex1072 26-02-2005 17:36

Re: ERROR
 
Quote:

Originally Posted by amateurrobotguy
I have made some progress. I got rid of all the error right down to the last lines:
MPLINK 3.40, Linker
Copyright (c) 2003 Microchip Technology Inc.
Error - could not find definition of symbol 'ceil' in file 'D:\Robot\MyFiles\user_routines.o'.
Errors : 1

All i did was this:

/************************************************** *****************************
* FILE NAME: user_routines.c <FRC VERSION>
*
* DESCRIPTION:
* This file contains the default mappings of inputs
* (like switches, joysticks, and buttons) to outputs on the RC.
*
* USAGE:
* You can either modify this file to fit your needs, or remove it from your
* project and replace it with a modified copy.
*
************************************************** *****************************/

#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
#include "user_Serialdrv.h"
#include <math.h>

extern unsigned char aBreakerWasTripped;

/*** DEFINE USER VARIABLES AND INITIALIZE tHEM HERE ***/

/* EXAMPLES: (see MPLAB C18 User's Guide, p.9 for all types)
unsigned char wheel_revolutions = 0; (can vary from 0 to 255)
unsigned int delay_count = 7; (can vary from 0 to 65,535)
int angle_deviation = 142; (can vary from -32,768 to 32,767)
unsigned long very_big_counter = 0; (can vary from 0 to 4,294,967,295)
*/
double ceil(double x);
double pow(double x, double y);

See two last lines. Am I going down the right path? If so, what is causing the error then?


Those two lines that you added are exactly what would have been in math.h. Unfortunatly you also need the actual code of the functions. The way libraries usually work in c is that you have a .h file that tells the compiler all the functions and variables defined in the library, and you have a .o file which contains the compiled code. The way a compiler works is that it takes code and then terns each file into a .o file. The .o file contains "object code". The oject code is an intermediary step between the source code and the actual .hex file. The linker then combines all the .o files into one .hex file. The error that you're getting now is because the compiler does sees all the definitions and compiles the user_routines file assuming that the ceil and pow functions exist. When the linker tries to link the object files though, it doesn't find the actual code for the ceil and pow functions. In order for this to work you have to make it so that MPLAB uses math.o as part of the project and links it in along with your code. Alternativly, you can find the source code to math.o, which would be math.c, and compile it as part of your project. Then the compiler would first compile math.c into a new math.o, and then the linker coud use that to create the .hex file.

amateurrobotguy 26-02-2005 17:42

Re: ERROR
 
What do I need to put in math.c to get my 2 functions to work?

amateurrobotguy 26-02-2005 19:31

Re: ERROR
 
1 Attachment(s)
I think I made a tiny bit of progress in finding a math.c Only problem is, I get this error.

Make: The target "D:\Robot\MyFiles\main.o" is up to date.
Make: The target "D:\Robot\MyFiles\user_SerialDrv.o" is up to date.
Make: The target "D:\Robot\MyFiles\user_routines.o" is up to date.
Make: The target "D:\Robot\MyFiles\user_routines_fast.o" is up to date.
Make: The target "D:\Robot\MyFiles\printf_lib.o" is up to date.
Make: The target "D:\Robot\MyFiles\ifi_utilities.o" is up to date.
Make: The target "D:\Robot\MyFiles\ifi_startup.o" is up to date.
Make: The target "D:\Robot\MyFiles\math.o" is out of date.
Executing: "D:\Robot\mcc18\bin\mcc18.exe" -p=18F8520 "math.c" -fo="math.o" /i"D:\Robot\mcc18\h" -D_FRC_BOARD -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
D:\Robot\MyFiles\math.c:65:Error [1302] old style function declarations not supported
Halting build on first failure as requested.
BUILD FAILED: Sat Feb 26 16:30:19 2005


All times are GMT -5. The time now is 11:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi