I have a problem that I think is related to my IDE. I am using Codeblocks (13.12).
Here's my "set up":
main.c (includes 'int main()')
header.h (your typical header, includes prototypes)
test.c (a random file, includes custom-made functions.)
Here's the issue: All the functions works as intended, but when I compile my test.c I get an error (for each function) saying: "error: redefinition of ***"
This issue doesn't affect anything, but it's annoying. I'm wondering if it's possible to get rid of it somehow? Maybe I'm doing something wrong when I'm creating my prototypes?
Here's an example of what my functions and prototypes look like:
void func_showMenu(); //This is the prototype, in header.h
void func_showMenu(){
//This is the function, in test.c
}
Is there some setting in Code::Blocks that can fix this issue?
I created a few test files to show the error:
Here's main.c:
#include "header.h"
int main(){
test();
testTwo();
return 0;
}
header.h:
#ifndef header.h
#define header.h
#include <stdio.h>
#include <stdlib.h>
#include "test.c"
void test();
void testTwo();
#endif
test.c:
#include "header.h"
void test(){
printf("Test works! \n");
}
void testTwo(){
printf("TestTwo also works! \n");
}
This is all there is, nothing more, nothing less.
When I run the program (main.c) it outputs:
"Test works!"
"TestTwo also works!"
So the program runs just fine.
But. Whenever I build (ctrl+F9) test.c I get the following errors:
C:\...\test.c|3|error: redefinition of 'test'|
C:\...\test.c|3|note: previous definition of 'test' was here|
C:\...\test.c|7|error: redefinition of 'testTwo'|
C:\...\test.c|7|note: previous definition of 'testTwo' was here|
||=== Build failed: 2 error(s), 3 warning(s) (0 minute(s), 0 second(s)) ===|
If I add more functions in test.c I will get one error like this for each function added.
Like I said: the program still runs and all, but it is very annoying.
Is there some way to fix this?