News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Linking problem?

Started by Bananskrue, August 29, 2012, 12:53:50 AM

Previous topic - Next topic

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


#include <cstdlib>
#include <iostream>

#include "functions.h"

using namespace std;

int main()
{
hello();
return 0;
}



functions.h



#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

void hello();

#endif // FUNCTIONS_H_INCLUDED


Hello.cpp


#include <cstdlib>
#include <iostream>

#include "functions.h"

using namespace std;

void hello()
{
cout << "Hello";
}


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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]