User forums > Using Code::Blocks
Linking problem?
(1/1)
Bananskrue:
This may just be me making a rookie mistake since I haven't programmed in a long, long time, but I'm getting some weird problems when I'm trying to divide my program into several source/header files.
The current program code looks a little bit something like this:
main.cpp
--- Code: ---
#include <cstdlib>
#include <iostream>
#include "functions.h"
using namespace std;
int main()
{
hello();
return 0;
}
--- End code ---
functions.h
--- Code: ---
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
void hello();
#endif // FUNCTIONS_H_INCLUDED
--- End code ---
Hello.cpp
--- Code: ---
#include <cstdlib>
#include <iostream>
#include "functions.h"
using namespace std;
void hello()
{
cout << "Hello";
}
--- End code ---
The error I am getting is: "Undefined reference to hello();" when it is called in the main.cpp file. If I include Hello.cpp in the header file, everything works fine and dandy, but that's obviously not the way to go. Am I missing something crucial here? All files are under the same project that I made in code::blocks. My SINCEREST apologies if I've either coded something wrong or this is as stated in the rules related to gnu cpp, however I thought all files under the project were supposed to be linked, whereas it does not seem this is the case?
Thanks!
oBFusCATed:
Read this: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
It will tell you how to enable full logging and then you can see what is compiled and what is linked.
Navigation
[0] Message Index
Go to full version