This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Compiling with gettimeofday


TV JOE wrote:

> gcc -I/usr/include/mingw -I/usr/include/mingw/sys GoCart_v04.c -lm

Stop right there.  You should *never* do this.  This is like filling a
gasoline car's tank with diesel -- it will not work and it will cause
breakage.  Mingw is a completely separate environment from Cygwin, you
can't just go mixing bits and pieces of each.  They use radically
different C runtimes.

If you want to use mingw, you need to use -mno-cygwin.  The include
paths will be adjusted accordingly.

This is quite a red herring though, because there's no need to use mingw
to call gettimeofday().

Also, -lm is never needed with Cygwin and does nothing.

> // Function to read system time.  Only used for testing execution speed.
> long int gettime(void)
> {
>  struct timeval ltim;
> 
>   gettimeofday(&ltim, NULL);
>   return (((long int)ltim.tv_sec)*((long int)(1000000))+((long
> int)ltim.tv_usec));
> }
> 
> My includes at the top of the
>  source code are as below.
> 
> // Inclusions
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> #include <math.h>
> #include <complex.h>
> 
> I've tried replacing time.h with unistd.h or including
> sys/time.h after time.h.  Any advice is welcome.

Rather than guesswork, why not look it up?  This is all standard stuff. 
It's defined by POSIX in the SUSv3. 
<http://www.opengroup.org/onlinepubs/009695399/functions/gettimeofday.html>. 
Struct timeval is defined in sys/time.h.  Your testcase works fine as
follows:

$ cat gettimeofday.c
#include <sys/time.h>

long int gettime(void)
{
 struct timeval ltim;

  gettimeofday(&ltim, NULL);
  return (((long int)ltim.tv_sec)*((long int)(1000000))+((long
int)ltim.tv_usec));
}

$ gcc -Wall -c gettimeofday.c
# no errors

Remove that mingw include stuff, include sys/time.h, and you should be
fine.  If you run into problems, enable -Wall and read the relevant docs
for each function that you call.  Don't try to just throw random headers
into the top of your file until it works.

And don't post fragments of files, post standalone test cases that can
be compiled.  If you only post snippets of a file then we have no idea
if the part you redacted contains the error.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]