Linux c++ compile errors that baffle me ...

For the first time, I am trying to write a program under Linux UBUNTU using gcc and I get some compilation results on one module that I hope somebody would be able to explain to me what I am doing wrong.

The command line I am using (with the redirection to a file) is:

LeLorrain@Tristram: ~/Programming/C++ $ gcc -std=c++11 sources/Timer.cpp 2> timer.err

Here is class declaration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef RD_GAME_TIMER_H_INCLUDED
#define  RD_GAME_TIMER_H_INCLUDED

using namespace   std;

namespace   RD_GAME
{
    class   Timer
    {
        public:
            Timer   ( void );
            ~Timer  ( void );

            inline void   Start               ( void );
            inline double Stop                ( void );
            inline int    getFPS              ( long elapsedFrames, bool lockFPS );
        private:
            inline double getElapsedSeconds   ( void );
            inline double getIntervalSeconds  ( void );

            uint        m_StartTime;        // Time when timer created / reset
            uint        m_LastTime;         // Time of last request
            uint        m_FrameTime;        // Time of last frame group
            uint        m_FpsTime;          // Time of last FPS check
            double      m_ElapsedTime;      // Time elapsed total
            double      m_TicksPerSecond;   // Timer frequency
    };
}
#endif // RD_GAME_TIMER_H_INCLUDED 


... the class declaration:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! ============================================================================
//! \brief  Timer.cpp Class definition
//! ============================================================================

#ifndef RD_GAME_COMMON_H_INCLUDED
#include "../headers/Common.h" // Game common definitions (System headers)
#endif
#ifndef RD_GAME_TIMER_H_INCLUDED
#include "../headers/Timer.h"
#endif

namespace     RD_Game
{
    Timer::Timer ( void )
    : m_StartTime      ( 0 ),
      m_LastTime       ( 0 ),
      m_ElapsedTime    ( 0.0f ),
      m_FrameTime      ( 0 ),
      m_FpsTime        ( 0 ),
      m_TicksPerSecond ( 0.0f ),
      m_TargetFPS      ( 0 )
     {
          m_TargetFPS = Globals::g_TargetFPS;
          return;
    }

    Timer::~Timer ( void )
    {
         return;
    }

    void Timer::Start ( void )
    {
         m_StartTime    = SDLGetPerformanceCounter();
         m_LastTime     = m_StartTime;
         m_FrameTime    = m_StartTime;
         m_FpsTime      = 0;
         return;
    }

    inline double Timer::getElapsedSeconds ( void )
    {
         m_LastTime = SDLGetPerformanceCounter ();
         return (double)((m_LastTime - m_StartTime)) / m_TicksPerSecond;
    }

    inline double Timer::getIntervalSeconds ( void )
    {
        int     currentTime     = SDLGetPerformanceCounter ();
        double  intervalSeconds = static_cast<double>(CurrentTime - m_LastTime) / static_cast<double>(m_TicksPerSecond);
        m_LastTime   = currentTime;

        return intervalSeconds;
    }

    int Timer::getFPS ( long elapsedFrames )
    {
         double fps         = 0.0f;
         int    currentTime = SDLGetPerformanceCounter ();

         if (m_FrameTime > 0)
         {
              fps = static_cast<double>(elapsedFrames) * m_TicksPerSecond / (double)(currentTime - m_FrameTime);

             if (m_TargetFPS > 0)
             {
                  double target = 1.0f / static_cast<double>(Globals::g_TargetFPS);
                  int  frameDelay = static_cast<int>((target - 1.0f / fps) * 1000.0f);
                  if ( frameDelay > 50 )
                  {
                      if (__DEBUG__)
                      { 
                            stringstream m_Message;
                            m_Message.clear();
                            m_Message << APPS_NAME << APPS_VERSION << "INFORMATION: -> Frame Delay = " << frameDelay << "ms" << ends;
                            Globals::Logging (m_Message.str());
                       }
                       usleep ( frameDelay * 1000 );
                   }
                }
          }
          m_FrameTime = currentTime;
          return static_cast<int>(fps + 0.5f);
     }

     inline double Timer::Stop ( void )
     {
          m_ElapsedTime += getElapsedSeconds ();
          return m_ElapsedTime;
     }
}     //! End RD_ 


... and here the complete results on the timer.txt file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sources/Timer.cpp:27:2: error: ‘Timer’ does not name a type; did you mean ‘time’?
  Timer::Timer   ( void )
  ^~~~~
  time
sources/Timer.cpp:52:2: error: ‘Timer’ does not name a type; did you mean ‘time’?
  Timer::~Timer       ( void )
  ^~~~~
  time
sources/Timer.cpp:63:2: error: ‘Timer’ does not name a type; did you mean ‘time’?
  Timer::Start        ( void )
  ^~~~~
  time
sources/Timer.cpp:80:2: error: ‘Timer’ has not been declared
  Timer::getElapsedSeconds ( void )
  ^~~~~
sources/Timer.cpp: In function ‘double RD_Game::getElapsedSeconds()’:
sources/Timer.cpp:83:3: error: ‘m_LastTime’ was not declared in this scope
   m_LastTime  = SDLGetPerformanceCounter ();
   ^~~~~~~~~~

... followed errors rejecting all the class data members suppressed 
Last edited on
Would you pleas be so kind and replace in your post [\code] by [/code], for more than just aesthetic reasons.
Have you tried removing the macros in your source file?

The guard macros are fine. Even for namespace, capitalization matters.
Those inclusions in the source are very foreign to me... If you're using gcc to compile c++ source code, shouldn't you also be linking the standard c++ library?
gcc -lstdc++ -std=c++11
Are you also using SDL? If so, I think you should be linking the SDL libraries as well...
@fiji885: The header "common.h" included in "Timer.ccp" include the necessary c++ libraries as well as the declaration of the class "Globals". I did not include because of the message limitations (9000 chars).
Also, a friend told me that I should not use "../headers/" but add it to gcc option (-I headers). Only, I compiled other class modules and the main without problems. So, the class in "Timer.h" compiles without errors with the definition module.
Last edited on
Well, as Duthomhas already mentioned, did you fix your namespace? Capitalization matters... One of them is RD_Games and the other is RD_GAMES.

LeLorrain wrote:

Only, I compiled other class modules and the main without problems.

Are you compiling them one by one into object files, and then linking them all together in the end? I just ask this because I have never compiled a main program without compiling all the other needed components first. I'm not even sure if you can do that.
@fiji885: Thanks, I changed it and the module compile without error! I could have read the code 1000 time and I would not have seen it. When I worked, we always had a colleague read our code to detect this king of errors!
Topic archived. No new replies allowed.