I am just playing around with code blocks and writing a very simple program, but I get the undefined reference error… I copied the exact same code to somewhere else and compiled it in the terminal and works fine, but just doesn’t work in code blocks.
my main.c is:
#include <stdio.h>
#include "subfunc.h"
int main()
{
printhello();
return 0;
}
and then my subfunc.c is:
#include <stdio.h>
#include "subfunc.h"
void printhello(void)
{
printf("hello world in function\n");
}
and then my subfunc.h is:
void printhello(void);
Thanks
UPDATE
Actually.. I figured it out. I right clicked the files subfunc.c and subfunc.h and select properties and went to build tab, I find the option for compile file and link file are not ticked. Thanks
You didn’t state exactly what the undefined error was but I’m betting it has something to do with either your
main()orprinthello()function.Make sure you’re linking both object files main.obj and subfunc.obj in your project after compiling your main.c and subfunc.c. This should automatically happen in codeblocks assuming you included both main.c and subfunc.c for the current project you’re building.