0

I'm using g++ command line under Windows 10 to build a basic timing loop and am getting the error: " undefined reference to `timeGetTime@0' " when attempting to compile.

The code, itself, is pretty simple:

#include <windows.h>
#include <iostream>
using namespace std;

int main(){
   int start = timeGetTime();
   int finish = 10000;
   int benchmarks [9] = {1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000};
   int i = 0;
   int time = timeGetTime() - start;
   while( time < finish){
       if(time > benchmarks[i]){
           cout << benchmarks[i] / 1000 << endl;
           i++;
       }

   return 0;
}

Not sure what I need to do to get g++ to play nicely with the WinAPI. I can't help but wonder if it's an issue with the linker.

Trey Roady
  • 27
  • 1
  • 2
  • 6
  • 2
    as per https://msdn.microsoft.com/en-us/library/windows/desktop/dd757629(v=vs.85).aspx you need to reference winmm.lib – pm100 Jun 07 '17 at 15:37
  • timeGetTime is a very poor function for measuring time for benchmarks. – The Techel Jun 07 '17 at 16:15
  • I'm not using it for benchmarks. I'm using it as a control function for peripherals which need to be activated according to a particular schedule. I just called the variable 'benchmarks' as a way of establishing points where I wanted responses. This is largely an early debug before I pass in the more detailed instructions – Trey Roady Jun 07 '17 at 16:40

1 Answers1

1

You have to link libwinmm.

Undefined reference is an error which occures when your compiler knows that the function exist, it knows its prototype, but can't find its corpse. When it is not one of your functions, it surely means you miss to link a library.

Gaulois94
  • 159
  • 9