Sign in to follow this  

Dev-C++ Linking problems

This topic is 4554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this