Reputation: 4376
In my prototype file, proto.h, I have
#define LOOP_LIMIT 90.00
#define PI 3.14159
#ifndef _PROTO_H
#define _PROTO_H
#include <stdio.h>
#include <math.h>
#include "get_problem.c"
#include "deg_to_rad.c"
#include "evaluate_sin.c"
#include "evaluate_cos.c"
#include "evaluate_tan.c"
int main(void);
int get_problem();
double deg_to_rad(int deg);
void evaluate_sin(int deg);
void evaluate_cos(int deg);
void evaluate_tan(int deg);
#endif
In my lab7.c I have my main function and I include proto.h. When I try to compile on Linux using the "make" command, I get the following message:
gcc -c deg_to_rad.c deg_to_rad.c: In function ‘deg_to_rad’:
deg_to_rad.c:2: error: ‘PI’ undeclared (first use in this function)
deg_to_rad.c:2: error: (Each undeclared identifier is reported only once
deg_to_rad.c:2: error: for each function it appears in.)
make: * [deg_to_rad.o] Error 1
I really don't understand this because my main function uses LOOP_LIMIT correctly, but PI isn't working.
deg_to_rad.c:
double deg_to_rad(int deg) {
double rad = (PI * deg) / 180;
return rad;
}
Upvotes: 0
Views: 132
Reputation: 206606
#include "get_problem.c"
#include "deg_to_rad.c"
#include "evaluate_sin.c"
#include "evaluate_cos.c"
#include "evaluate_tan.c"
NO NO, You shouldn't be including C files!!!
In general, You declare functions in header(.h) files, define them in source files(.c) and include the header files in source files(.c) wherever you need to use the functions.
Also, show the definition of deg_to_rad()
function, the compiler clearly tells you the problem lies there, I suspect you try to call one of the other functions in the function.
The compiler rightly complains because the functions are declared after the point where you include the source file.
You need to follow the general practice of header and source files mentioned above.
Upvotes: 5