I am using a makefile to compile a program that consists of several files. The error that I'm getting is:
/tmp/ccwntKP7.o: In function 'main':
test.driver.c
.text+0x17f): undefined reference to 'PrintWhere'
collect2: ld returned 1 exit status
make: *** [test-driver] Error 1
I'm compiling with makefile, so the commandline reads make test-driver. The file is set up to read the command line:
cc -g -o test-driver test-driver.c c-warmup.o
The test-driver file calls the function PrintWhere this way:
#include "c-warmup.h"
#define DB "c-warmup.db"
int main (int argc, char *argv[])
{
float minGpa = 3.5;
float failGpa = 2.0;
float maxGpa = 4.0;
float eqGpa = 3.2;
int testId = 247;
char testName[80];
strcpy (testName, "Frye, John");
printf ("***************************************************************\n");
printf ("Names, ages of students in file %s \n with name > '%s'\n", DB, testName);
printf ("***************************************************************\n");
PrintWhere (DB, STRUCTSIZE, NAME_OFFSET, STRING, AGE_OFFSET, INTEGER, NAME_OFFSET,
STRING, GREATER, testName);
printf ("\n");
printf ("***************************************************************\n");
printf ("Names, id's of students in file %s \n with id > %d\n", DB, testId);
printf ("***************************************************************\n");
PrintWhere (DB, STRUCTSIZE, NAME_OFFSET, STRING,ID_OFFSET, INTEGER, ID_OFFSET,
INTEGER, GREATER, (char *) &testId);
printf ("\n");
printf ("***************************************************************\n");
printf ("Names, gpa's of students in file %s \n with gpa < %3.1f\n", DB, failGpa);
printf ("***************************************************************\n");
PrintWhere (DB, STRUCTSIZE, NAME_OFFSET, STRING, GPA_OFFSET, FLOAT, GPA_OFFSET,
FLOAT, LESS, (char *) &failGpa);
printf ("\n");
printf ("***************************************************************\n");
printf ("Names, ages of students in file %s \n with gpa = %3.1f\n", DB, maxGpa);
printf ("***************************************************************\n");
PrintWhere (DB, STRUCTSIZE, NAME_OFFSET, STRING, AGE_OFFSET, INTEGER, GPA_OFFSET,
FLOAT, EQUAL, (char *) &maxGpa);
return (0);
}
PrintWhere is created in a seperate file called cwarmup.c, which is called in cwarmup.h
int
PrintWhere (
char *fileName, /* name of the file of records */
int recSize, /* size of each record in bytes */
int fieldOffset1, /* offset of field 1 in record */
char fieldType1, /* field 1 type: 'i', 'f', or 's' */
int fieldOffset2, /* offset of field 2 in record */
char fieldType2, /* field 2 type: 'i', 'f', or 's' */
int fieldOffset3, /* offset of field 3 in record */
char fieldType3, /* field 3 type: 'i', 'f', or 's' */
char compareOp, /* comparison type: '<', '=', or '>' */
char *valPtr) /* pointer to comparison value */