1

Alright I'm pretty new to using VS. I'm trying to figure out the time elapsed between updates in an OpenGl program (in C), and I was planning on using timeGetTime().

I have

#include <windows.h>

at the top of my program. As well under "Project>Properties>Linker>Input", I have "Additional Dependencies" include "winmm.lib". Now whenever I try to use timeGetTime(), it gives me two errors:

Error   63  error LNK2019: unresolved external symbol _timeGetTime referenced in function _main ***.obj 

and

Error   64  fatal error LNK1120: 1 unresolved externals C:\***  

How do I get around this?

2 Answers 2

5

Make sure you don't have WIN32_LEAN_AND_MEAN or MMNOTIMER macros defined, or the prototype for timeGetTime() won't be included in mmsystem.h .

Another possibility is that you have some other declaration for timeGetTime() in one of your headers (or the .c source file) that's being picked up for some reason instead of the declaration in mmsystem.h.

The symbol that should be looked for by the linker is:

__imp__timeGetTime@0 (or __imp_timeGetTime on x64)

not

_timeGetTime
4
  • These are my other header files I've included: #include <gl/freeglut.h> #include <math.h> #include <stdlib.h> #include <windows.h> I don't know if any of them declare timeGetTime (besides windows.h when it includes mmsystem.h). I have no idea how to use macros, how could I check if WIN32_LEAN_AND_MEAN is defined?
    – Jeff
    Feb 15, 2011 at 2:29
  • @Jeff: you'd either have a #define WIN32_LEAN_AND_MEAN in your source file (or a header), or you'd have it in the project settings' "Preprocesor definitions" item. You can try putting an #undef WIN32_LEAN_AND_MEAN just before your #include <windows.h> to see if that's the culprit or not. You might also try putting windows.h before the other includes but that shouldn't usually be a requirement (except for the oddball case of winsock2.h, which to avoid conflicts has to be included before windows.h if you're using it). Feb 15, 2011 at 5:12
  • I just had a look at freeglut.h - it results in WIN32_LEAN_AND_MEAN being defined (at least the version I looked at). You'll need to include windows.h before that header. Feb 15, 2011 at 5:35
  • Ah thank you so much, it works now! I should've had a look through freeglut myself.
    – Jeff
    Feb 15, 2011 at 12:40
0

If you're trying to do timings, I'd recommend using QueryPerformanceFrequency and QueryPerformanceCounter instead of timeGetTime. These work by using the high performance counters in Windows, which will give you much better accuracy for timings.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.