I'm working on my own math library, and I have a couple of non-member functions in the namespace I'm using for the library ("cml", like it matters much). Anyway, the library (which I'm building statically as a .a/.lib file) compiles just fine, but when I go to use the library in a test program, I get an error that the functions are undefined references.
This is header (func.h) file:
namespace cml
{
template <typename T>
T toRadians(T val);
template <typename T>
T toDegrees(T val);
template <typename T>
T fastSqrt(T val);
template <typename T>
T fastInverseSqrt(T val);
}
And this is the func.cpp file:
#include <CML/func.h>
#include <cmath>
#include <math.h>
#include <limits>
#include <cassert>
namespace cml
{
template <typename T>
T toRadians(T val)
{
static_assert(std::numeric_limits<T>::is_iec559, "toRadians() requires the template parameters to be floating points.");
return val * MATH_PI / 180;
}
template <typename T>
T toDegrees(T val)
{
static_assert(std::numeric_limits<T>::is_iec559, "toDegrees() requires the template parameters to be floating points.");
return val * 180 / MATH_PI;
}
template <typename T>
T fastSqrt(T val)
{
static_assert(std::numeric_limits<T>::is_iec559, "fastSqrt() requires the template parameters to be floating points.");
return T(1) / fastInverseSqrt(val);
}
template <typename T>
T fastInverseSqrt(T val)
{
static_assert(std::numeric_limits<T>::is_iec559, "fastInverseSqrt() requires the template parameters to be floating points.");
T tmp = val;
T half = val * T(0.5);
uint32* p = reinterpret_cast<uint32*>(const_cast<T*>(&val));
uint32 i = 0x5f3759df - (*p >> 1);
T* ptmp = reinterpret_cast<T*>(&i);
tmp = *ptmp;
tmp = tmp * (T(1.5) - half * tmp * tmp);
#if defined(CML_ACCURATE_FUNC) // If more accuracy is requested, run Newton's Method one more time
tmp = tmp * (T(1.5) - half * tmp * tmp);
#endif // defined
return tmp;
}
}
I am getting the error for all four of the functions. I am using the latest version of Code::Blocks, with GCC on Windows8. I am compiling for Win32. I've tried different suggestions I've found like marking the functions extern, but it doesn't seem to fix it. I'm sure it's something simple I'm missing, and if that is the case a second pair of eyes might help.
The error exactly: undefined reference tofloat cml::toRadians(float)'`