delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/04/28/22:44:14

X-Spam-Check-By: sourceware.org
Message-ID: <4452D307.114E412F@dessent.net>
Date: Fri, 28 Apr 2006 19:44:23 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Compiling with gettimeofday
References: <20060429022227 DOT 15207 DOT qmail AT web35715 DOT mail DOT mud DOT yahoo DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019