Undefined reference to function.

Hello Everybody!

This is my first post here! Please be gentle ;)
I am including a header file from another directory into my code which I write using codeblocks.

But I get the following error message:

Undefined reference to M_NS_t

Although I included the directory in using project > build options > search directory.

It's just very simple code:


1
2
3
4
5
6
7
8
9
10
11
12
#include <cmath>
#include "sigma_0.h"
#include "coefficient_functions.h"
#include "dglap_equation/evolution_equation.h"

double NS_CS(double s, double e_q, double T3_q, double mu_R, double n_f,
			double N, double Q, double mu, double t, double alpha, double beta, double n)
{
    return 	sigma_0(s, e_q, T3_q) * C_NS_T_q(mu_R, n_f, N, Q, mu)
			* M_NS_t(mu_R, n_f, t, alpha, beta, N, n);
}


Code anyone help me get rid of the error? Generally how do I include header files from other directories?
Last edited on
An "undefined reference" is a linking error. If your code compiled, you got the including of the header files correct. The problem is, the compiler can't find the object code where the function M_NS_t is defined. You need to link against the library where it is defined.
Thank you cire for the answer.

Problem is, in the directory I have a collection of .cpp and .h files but I didn't create library files. But I do get your point, apparently the header file is included correctly but the the object code can't be found and I think this is absolutely the case.

Yet I do not understand "link against the library files", should I create the library files and link against them?
Yet I do not understand "link against the library files", should I create the library files and link against them?

If you haven't, you might consider just adding the source files to your project (although if you plan to re-use that code in other projects generating a library and linking against it will save you some time down the road.)
Thank you very much cire!

I'll generate the libraries then.
Topic archived. No new replies allowed.