Skip to main content
GameDev.net gamedev.net
🔒 Locked

Linker not linking timeGetTime (solved)

Started by Alpha_ProgDes Jan 10, 2005 at 12:08 PM 6 replies 27.6k views
Original Post
Alpha_ProgDes
Alpha_ProgDes
so here's the code:

#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{
  DWORD startime, endtime, lapsetime;
  startime = timeGetTime() ;
  string name = "Hello there, me.";
  endtime = timeGetTime() ;
  lapsetime = endtime - startime;
  cout << "Time is for string printing is (fps): " << 1.0f/lapsetime << endl;
  system("PAUSE");
  return 0;
}
here are the errors: c:\dev-c++\projects\c_test.o(.text+0x6a):c_test.cpp: undefined reference to timeGetTime@0' c:\dev-c++\projects\c_test.o(.text+0xa9):c_test.cpp: undefined reference to timeGetTime@0' I'm using Dev-C++ 4.01. The library directory (which holds the libwinmm.a) is already entered in compiler options. Yet I'm still getting these errors. Anyway idea why? Oh. I made this as a C++ console project. But don't worry I tried it as a Win32 Project and got the same errors [smile] [Edited by - Alpha_ProgDes on January 10, 2005 12:45:04 PM]
Beginner in Game Development?  Read here. And read here.  
Khaosifix
Khaosifix
Since the IDE uses the mingw compiler the order in which you link plays a significant role to compilation.

Type in '-lwinmm' in the linker option.
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
Pipo DeClown
Pipo DeClown
You'll have to link it to your project (just having it in the directory isn't enough). I don't have Dev-CPP installed right now, but it's somewhere at:

Projects -> Settings -> Linking Options, then the most right textbox. Just type '-libwinmm.a' in it.
pex22
pex22
It doesn't seem like the compiler knows where timeGetTime() is defined (in mmsystem.h there is only DWORD timeGetTime(VOID); . By the way, windows.h includes mmsystem.h).
From MSDN, you need to link Winmm.lib.
I think in Dev-Cpp, you need to add -lwinmm (it is probably defined in libwinmm.a in GCC)
pex.
Alpha_ProgDes
Alpha_ProgDes
You are right!! Thank you all.
It seems silly though that you have to do that to access any library. But anyway.
#include <windows.h>#include <windowsx.h>#include <iostream>#include <string>#include <ctime>#include <cstdlib>#include <mmsystem.h>using namespace std;int main(int argc, char *argv[]){  DWORD startime, endtime, lapsetime;  startime = timeGetTime() ;  string name = "Hello there, me.";    for (int i = 0; i < 50; ++i) {    int base = 6;    int newnum = 6 >> (i % 6);    newnum <<= i;    cout << newnum << endl;  }      endtime = timeGetTime() ;  lapsetime = endtime - startime;  cout << "Time is for string printing " << name << "is (fps): " << 1.0f/(1000.0f*lapsetime) << endl;  system("PAUSE");  return 0;}


That's correct for finding frames per second right?
Beginner in Game Development?  Read here. And read here.  
pex22
pex22
Using libraries is useful if you want to keep your source code from others (im not talking about DLLs)
And for your question, I don't think so. what will happen if the loop takes 2 seconds and there are more frames in the first second than the second second?
For converting from millisecond to second, you need to mult it in 0.001, no 1000.
All you need (for each frame) is to save the last frame in seconds, and check if lastframe-currentframeinseconds (current time in ms * 0.001) is bigger than (or equal to) 1 (a second).
If it is, then you have an updated fps. else, continue to the next frame.

pex.
pex.
Pipo DeClown
Pipo DeClown
If Dev-Cpp would automatically link to all of the libraries, your executable would be bigger. And there's no option where it automatically links to the necessary libraries, it there?
Alpha_ProgDes
Alpha_ProgDes
not that i saw.
i hope you weren't chewing me out.
that would make me [sad]
Beginner in Game Development?  Read here. And read here.  

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.