3

I have some code that I am cross compiling on Linux with MinGW/Wine (there are windows libraries that I am being forced to use). So I am compiling on Linux with g++.exe

I have a need in this code to get the current time with millisecond resolution. When compiling with standard g++, I usually use something like this:

struct timespec now;
clock_gettime(CLOCK_REALTIME,&now);

This gives the error:

error: aggregate 'time2()::timespec now' has incomplete type and cannot be defined

What is the equivalent that I can use that would work with g++.exe compiler?

EDIT, the compilation cmd is:

g++.exe -std=c++0x -g -Wall -O2 -o test.exe test.cpp
user788171
  • 16,753
  • 40
  • 98
  • 125
  • click on timespec see which header it points. – qwr Dec 22 '13 at 09:25
  • I have both #include and #include and still the same error. – user788171 Dec 22 '13 at 09:32
  • 2
    if you do `g++ -M myfile.cpp` you'll get a list of files that `myfile.cpp` is including. Check that all of the headers that you are including are actually the "windows version". To me, this looks very much like "mixed up headers" – Mats Petersson Dec 22 '13 at 09:37
  • 2
    If you're willing to use some Win32 calls in your code, you could switch to using the high-res performance counters, even from MinGW. (I use them in my cross-platform Intellivison emulator to great effect.) This article describes how to use them: http://cplus.about.com/od/howtodothingsi2/a/timing.htm You can see how I used them in my own code here: http://spatula-city.org/~im14u2c/intv/jzintv-1.0-beta4/src/plat/plat_lib.c (Scroll down to `WIN32_LEAN_AND_MEAN` ) – Joe Z Dec 22 '13 at 10:09
  • @MatsPetersson, can you elaborate on what you mean? You mean I should include something like #include instead? How do I find the names of the windows versions? Passing -M option gives no output. – user788171 Dec 22 '13 at 16:28
  • The compiler error means that `struct timespec now` is being interpreted as a declaration of a new type, which means the right header for `timespec` has not been included. Since you're writing C++ you can just say `timespec now` without `struct`, but that doesn't solve the problem of the Win32 `` header not defining `timespec`. – Jonathan Wakely Dec 22 '13 at 16:32

0 Answers0