Dev-C++ Linking problems

Started by
2 comments, last by Cornflake420 18 years, 9 months ago
I recently started a project in Dev-C++ version 4.9.9.2. When I try to compile, the linker returns with several errors: [Linker error] undefined reference to `os::Timer::initTimer(void)' [Linker error] undefined reference to `os::Timer::getTime(void)' [Linker error] undefined reference to `os::Timer::getTimer(void)' My project has a few files: - main.cpp - os.cpp Both include 'os.h', which contains the following:

class Timer
{
 public:
  static inline void initTimer( );
  static inline u32 getTime( );
};

In 'os.cpp', the functions are defined.

inline void Timer::initTimer( )
{
    // The variables below are defined globally and don't
    // seem to be part of the problem.
    bUseHighFreq = QueryPerformanceFrequency( &sHighFreq );
};

inline u32 Timer::getTime( )
{
    if( bUseHighFreq )
    {
        LARGE_INTEGER sTime;
        QueryPerformanceCounter( &sTime );
        return u32( ( sTime.QuadPart ) * 1000 + ( sHighFreq.QuadPart / 1000 ) );
    };
    return GetTickCount( );
};

The code in 'main.cpp' is a test function that is very simple.

int main( )
{
    using namespace os;

    Timer::initTimer( );
    Tell( "Start:\t%i", Timer::getTime( ) );
    for( int i = -32000; i < 32000; i++ )
        sqrt( cos( sin( 81 ) ) );    // This is just to waste some time.
   
    Tell( "End:\t%i", Timer::getTime( ) );

     system( "PAUSE" );
    return 0;
};

I clearly declared the functions before using them, and defined them within the project. Please help me figure out why I am getting these errors.
Advertisement
inline methods must be implemented in the header. The compiler has to expand them at compile time. With the implementations hidden in os.cpp, the compiler can't see them when compiling main.cpp.
Darn, wish I'd seen this one before. Yeah, if you want it inline, you'll need to declare it "inline". =D.
Things change.
Thanks a lot. Your suggestions worked.

This topic is closed to new replies.

Advertisement