Linker problems with inline functions

closed account (10oTURfi)
So... After alot of headaches I figured that this is causing linker errors:
(since code is rather large, I simplified it alot)
1
2
//Somewhere in console.h
inline int urand(int MIN, int MAX);

...
1
2
3
4
5
6
//Somewhere in console.cpp
//Include guards here
inline int urand(int MIN, int MAX)
{
    return (rand()%(MAX-MIN+1) + MIN);
}

...
1
2
3
4
5
6
7
8
//Somewhere in myClass.cpp
#include "console.h"

myClass::myClass()
{
    //Init age
    blahblah = urand(0, 4);
}


And the compiler says this:
1>LINK : C:\Documents and Settings\Drago\Desktop\Mislav\Console Learning Project\Console-Learning-Project\Debug\Console Learning Project.exe not found or not built by the last incremental link; performing full link
1>myClass.obj : error LNK2019: unresolved external symbol "int __cdecl urand(int,int)" (?urand@@YAHHH@Z) referenced in function "public: __thiscall myClass::myClass(void)" (??0myClass@@QAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol "int __cdecl urand(int,int)" (?urand@@YAHHH@Z)
1>C:\Documents and Settings\Drago\Desktop\Mislav\Console Learning Project\Console-Learning-Project\Debug\Console Learning Project.exe : fatal error LNK1120: 1 unresolved externals


Is there a way to use that inline function I defined in console.h in a constructor of a class?
Last edited on
You didn't defined it in console.h (you just declare it)
inline and template functions must be in headers.

Also, header (include) guards are for headers, not for sources.
Last edited on
Topic archived. No new replies allowed.