Code::Blocks Forums
User forums => General (but related to Code::Blocks) => Topic started by: Anark10n on April 22, 2010, 01:17:03 pm
-
Hey there
New to the forum, searched all over for an answer to the problem I'm having, didn't find it. New to using code blocks as well, got a problem with including my header files, probably with linking, not sure, but it keeps giving me the same error message: undefined reference to '_<function_name>'. Any clarity on the problem would be appreciated. Side note: the code compiles without problem in visual studio express.
Thanks in advance to anyone who replies...
-
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
You have a linking problem... probably missing file or library
-
Side note: the code compiles without problem in visual studio express.
FYI:
Visual Studio can automatically include some libraries and also uses #pragma commands to include libraries.
Tim S
-
Thanks for the replies, but it is still giving me the same error message. Thought it might just windows only bug so i tried it on a Linux machine seeing as it usually comes with the GCC compiler pre-installed with all the necessary files, and it still gave me the same error message.
-
The problem can happen, if you mix c++-code with c-code.
If that's the case, you should read this: http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html (http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html) .
-
I doubt it's a mix of c and c++, see for yourself:
My header file: Largest.h
int maximum(int x, int y, int z);
My function definitions: LargestDef.c
#include "Largest.h"
int maximum(int x, int y, int z)
{
int maxNum = x;
if (maxNum < y)
{
maxNum = y;
}
if (maxNum < z)
{
maxNum = z;
}
return maxNum;
}
My main function
#include <stdio.h>
#include "Largest.h"
int main()
{
int num1;
int num2;
int num3;
printf("Enter three integers: ");
scanf("%d %d %d", &num1, &num2, &num3);
printf ("Largest: %d", maximum(num1, num2, num3));
return 0;
}
Not certain whether its appropriate to post code samples here, so apologies if it is not.
-
I doubt it's a mix of c and c++, see for yourself:
I suggest turning on full compiler logging.
Or, renaming main.cpp to main.c (if it was named wrong).
Tim S.
-
File containing the main function is also a .c file, sorry about the omission. As for the solutions, no luck; being new to code blocks, i don't exactly know what it is I'm supposed to look for in the compiler logs. Not a surprise though that it compiles fine if i chuck all the code in the same file.
-
Read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
-
Thanks for the help, played around with the compiler options (had to look in a lot of places to figure it out), got everything to link properly. Not the most elegant of solutions, but at least it works. Great IDE by the way, hooray for open source...