Trying to call a function from another file in C with the following code:
main.c
#include "display.h"
int main()
{
display_options();
display_price();
return 0;
}
display.h
int display_options(void);
int display_price(void);
display.c
#include <stdio.h>
int display_options()
{
printf("Welcome to the pizza parlor\n");
printf("What size pizza would you like? (in inches)");
return 0;
}
int display_price()
{
printf("Your pizza will cost 0.00\n");
return 0;
}
I created this following an example here http://www.faqs.org/docs/learnc/x307.html but it doesn’t seem to be working i get an error message in codeblocks 10.05 on the function called in main.c saying “undefined reference to ‘display_options'”
In Code::Blocks, you need to make sure that
display.cis in your project (if you haven’t created a project, do so now) and that it’s also included in one or more build targets.debugandreleasebuild targets are created by default, but nothing is added to a target unless you say so. When you create a new file or add an existing file to a project, the IDE should ask you which targets to add the file to. Select all of them and hit OK.If your file is already in the project but not included in any target, go to Project | Properties | Build targets and make sure that the Build target files panel shows checkmarks beside both
main.canddisplay.c.