undefined reference to 'timeGetTime@0'

I'm in trouble at finding the proper library for timeGetTime() function. When i try to run it, it give me this error: "undefined reference to 'timeGetTime@0'". I have win 8.1 on my pc.

1
2
3
4
5
6
7
8
9
10
11
12
13
//c++ program
  #include <iostream>
  #include <ctime>
  #include <windows.h>
   using namespace std;
    int main()
{DWORD t=timeGetTime();
int i;
for(i=1;i<=10000;i++)
cout<<i<<"\n";
t=timeGetTime()-t;
cout<<"t="<<t;
return 0;}

I also tried to include winmm.lib as a header but this error shows up: "no such file or directory".
Now please tell me, what am i doing wrong? And if there is any solution, please try to describe it step by step (i'm a trully beginner). Thank you!
Did you use this?

1
2
3
4
5
#include <iostream>
#include <ctime>
#include <windows.h>

#pragma comment( lib, "winmm.lib")   


You cannot include it as a header.

#include <winmm.lib>
Oh, yeah, i've just used it. And this is the result: "warning: ignoring #pragma comment". Is there another lead?
What C++ compiler are you using? Probably not Visual Studio.
I use gnu c++ and i work in codeblocks. And i also tried to include the library in the linker from build options , but when i restart codeblocks and puts in the program above, this is what appear : " ld.exe cannot find -lwinmm.exe".
But if this matters, i didn't actually browse the library, i just typed in "winmm.lib".
Ook i figured it out, i was given the error because of .lib suffix. Now i have another question. How to convert time given by that function into seconds? In fact, what i mean is that i don't know exactly what that time is expressed in , whether ms, or seconds, or something else?
The time you get from timeGetTime() is already measured in milliseconds.

To get seconds, divide it the time with 1000.00.

cout<< "t = " << t / 1000.00 << " sec.";
How to convert time given by that function into seconds?
See this:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd757629(v=vs.85).aspx

The result is ms.
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
#include <iostream>
#include <ctime>
#include <chrono>

int main()
{
    {
        // http://en.cppreference.com/w/cpp/chrono/c/time
        const std::time_t start = std::time(nullptr) ; // C wall clock time point

        // http://en.cppreference.com/w/cpp/chrono/c/localtime
        // http://en.cppreference.com/w/cpp/chrono/c/asctime
        std::cout << std::asctime( std::localtime( std::addressof(start) ) )
                  << "hit enter to continue..." ;

        std::cin.get() ;

        const std::time_t end = std::time(nullptr) ; // C wall clock time point

        // http://en.cppreference.com/w/cpp/chrono/c/difftime
        std::cout << std::asctime( std::localtime( std::addressof(end) ) )
                  << std::difftime( end, start ) * 1000.0 << " elapsed milliseconds\n" ;
    }

    {
        using namespace std::chrono ;

        // http://en.cppreference.com/w/cpp/chrono/steady_clock
        // http://en.cppreference.com/w/cpp/chrono/steady_clock/now
        const auto start = steady_clock::now() ; // steady clock time point

        std::cout << "\nhit enter to continue..." ;
        std::cin.get() ;

        const auto end = steady_clock::now() ; // steady clock time point

        // http://en.cppreference.com/w/cpp/chrono/duration/duration_cast
        // http://en.cppreference.com/w/cpp/chrono/duration/count
        std::cout << duration_cast<milliseconds>(end-start).count() << " elapsed milliseconds\n" ;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <iomanip>
#include <Windows.h>

int main()
{
  SYSTEMTIME st = {0};

  ::GetSystemTime(&st);

  std::cout.fill('0');
  std::cout << "Current Time: " << std::setw(2) << st.wHour << ":" 
            << std::setw(2) << st.wMinute << ":" << std::setw(2) 
            << st.wSecond << "\n";

  std::cout << "Windows running since : " << ::GetTickCount() <<" ms\n\n";
  system("pause");
  return 0;
}
Ok, thank you!
Topic archived. No new replies allowed.