Code::Blocks Forums
Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: Alexandwich on December 14, 2014, 01:12:33 pm
-
I started a project with multiple files (all are .h or .c) in C. For some reason a function declared in a .h file can't be used in the main file even if the .h is included at the top of the file. The only solution that i found was to link the .h file but it gives me another error:
.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
-
Don't do this or you'll enter the unpleasant lands of precompiled headers.
Undefined reference error means that you have not defined the function that is mentioned in the error message.
This means that you have not placed the code for the function in a .c file that is being compiled and linked.
-
I tried including the .c file instead in the main and now the function is usable however it now says
multiple definition of
so i tried adding a guard but it doesn't change anything
-
Including .c files should be done only by people who know what they're doing!
You're not one of them yet, so don't do it.
Have you checked our FAQ and especially this item:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F ?
-
I changed the extention of the main file (I didn't notice it was called main.cpp and not main.c) now it works thanks for the help anyway