I am new to C language. I have an assignment, in which I have to make use of multi-module concept to compile a program. I keep getting 'undefined reference' error. The program simply converts farenheit to celsius; if I use only one script which includes function prototype,call and definition it simply works, but with multi-module concept, it keeps yielding 'undefined reference' error. Do I have to put all the three files in different or same folder?
conversion.c:
/*
* filename: conversion.c
* Purpose: The file contains function prototype
* to convert farenheit to celsius
*/
#include "conversion.h"
//conversion for farenheit to celsius
float convertTemp(float tmp)
{
return ((tmp-32)*0.555);
}
conversion.h:
/*
* FILENAME: conversion.h
* PURPOSE: The file contains function prototype
* for conversion.c
*/
float convertTemp(float tmp);
convert_driver.c:
/*
* FILENAME: convert_driver.c
* PURPOSE: The file contains main() function
* and user interface.
*/
#include <stdio.h>
#include "conversion.h"
int main(void)
{
float x,y;
printf("Please enter your temperature for conversion: \n");
scanf("%f", &x);
y = convertTemp(x);
printf("Converted Temperature: %0.2f\n", y);
return 0;
}
I keep getting error for the line:
y=convertTemp(x)
Any help would be appreciated.
gcc *.c, otherwise you can fetch your files individually and directly with something such asgcc first_file.c /tmp/somewhere/second_file.c [...]. In your specific case, considering your files are in the same folder, you'd have to do:gcc convert_driver.c conversion.c.gcc -Wall -Wextra -o convert_driver convert_driver.c conversion.c(where-Wall -Wextraenable warnings which you should include every time you compile and do not accept code until it compiles without warning). You can also compile each to object individually (e.g.gcc -c -o conversion.o conversion.csame for convert_driver and then link withgcc -o convert_driver convert_driver.o conversion.o